This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: ithreads doesn't like usedl=n
[perl5.git] / ext / File / Glob / Glob.xs
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4
5 #include "bsd_glob.h"
6
7 /* XXX: need some thread awareness */
8 static int GLOB_ERROR = 0;
9
10 #include "constants.c"
11
12 #ifdef WIN32
13 #define errfunc         NULL
14 #else
15 int
16 errfunc(const char *foo, int bar) {
17   return !(bar == ENOENT || bar == ENOTDIR);
18 }
19 #endif
20
21 MODULE = File::Glob             PACKAGE = File::Glob
22
23 void
24 doglob(pattern,...)
25     char *pattern
26 PROTOTYPE: $;$
27 PREINIT:
28     glob_t pglob;
29     int i;
30     int retval;
31     int flags = 0;
32     SV *tmp;
33 PPCODE:
34     {
35         /* allow for optional flags argument */
36         if (items > 1) {
37             flags = (int) SvIV(ST(1));
38         }
39
40         /* call glob */
41         retval = bsd_glob(pattern, flags, errfunc, &pglob);
42         GLOB_ERROR = retval;
43
44         /* return any matches found */
45         EXTEND(sp, pglob.gl_pathc);
46         for (i = 0; i < pglob.gl_pathc; i++) {
47             /* printf("# bsd_glob: %s\n", pglob.gl_pathv[i]); */
48             tmp = sv_2mortal(newSVpvn(pglob.gl_pathv[i],
49                                       strlen(pglob.gl_pathv[i])));
50             TAINT;
51             SvTAINT(tmp);
52             PUSHs(tmp);
53         }
54
55         bsd_globfree(&pglob);
56     }
57
58 INCLUDE: constants.xs