Commit | Line | Data |
---|---|---|
72b16652 GS |
1 | #include "EXTERN.h" |
2 | #include "perl.h" | |
3 | #include "XSUB.h" | |
4 | ||
5 | #include "bsd_glob.h" | |
6 | ||
df3728a2 | 7 | #define MY_CXT_KEY "File::Glob::_guts" XS_VERSION |
89ca4ac7 JH |
8 | |
9 | typedef struct { | |
10 | int x_GLOB_ERROR; | |
11 | } my_cxt_t; | |
12 | ||
13 | START_MY_CXT | |
14 | ||
15 | #define GLOB_ERROR (MY_CXT.x_GLOB_ERROR) | |
72b16652 | 16 | |
1cb0fb50 | 17 | #include "const-c.inc" |
72b16652 GS |
18 | |
19 | #ifdef WIN32 | |
20 | #define errfunc NULL | |
21 | #else | |
f681a178 | 22 | static int |
72b16652 | 23 | errfunc(const char *foo, int bar) { |
5f18268b | 24 | return !(bar == EACCES || bar == ENOENT || bar == ENOTDIR); |
72b16652 GS |
25 | } |
26 | #endif | |
27 | ||
28 | MODULE = File::Glob PACKAGE = File::Glob | |
29 | ||
b84cd0b1 NC |
30 | int |
31 | GLOB_ERROR() | |
32 | PREINIT: | |
33 | dMY_CXT; | |
34 | CODE: | |
35 | RETVAL = GLOB_ERROR; | |
36 | OUTPUT: | |
37 | RETVAL | |
38 | ||
89ca4ac7 JH |
39 | BOOT: |
40 | { | |
41 | MY_CXT_INIT; | |
42 | } | |
43 | ||
72b16652 GS |
44 | void |
45 | doglob(pattern,...) | |
46 | char *pattern | |
e3de7a34 | 47 | PROTOTYPE: $;$ |
72b16652 GS |
48 | PREINIT: |
49 | glob_t pglob; | |
50 | int i; | |
51 | int retval; | |
52 | int flags = 0; | |
53 | SV *tmp; | |
54 | PPCODE: | |
55 | { | |
89ca4ac7 JH |
56 | dMY_CXT; |
57 | ||
72b16652 GS |
58 | /* allow for optional flags argument */ |
59 | if (items > 1) { | |
60 | flags = (int) SvIV(ST(1)); | |
61 | } | |
62 | ||
63 | /* call glob */ | |
64 | retval = bsd_glob(pattern, flags, errfunc, &pglob); | |
65 | GLOB_ERROR = retval; | |
66 | ||
67 | /* return any matches found */ | |
68 | EXTEND(sp, pglob.gl_pathc); | |
69 | for (i = 0; i < pglob.gl_pathc; i++) { | |
70 | /* printf("# bsd_glob: %s\n", pglob.gl_pathv[i]); */ | |
d3d34884 NC |
71 | tmp = newSVpvn_flags(pglob.gl_pathv[i], strlen(pglob.gl_pathv[i]), |
72 | SVs_TEMP); | |
72b16652 GS |
73 | TAINT; |
74 | SvTAINT(tmp); | |
75 | PUSHs(tmp); | |
76 | } | |
77 | ||
78 | bsd_globfree(&pglob); | |
79 | } | |
80 | ||
1cb0fb50 | 81 | INCLUDE: const-xs.inc |