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 | ||
72b16652 GS |
39 | void |
40 | doglob(pattern,...) | |
41 | char *pattern | |
e3de7a34 | 42 | PROTOTYPE: $;$ |
72b16652 GS |
43 | PREINIT: |
44 | glob_t pglob; | |
45 | int i; | |
46 | int retval; | |
47 | int flags = 0; | |
48 | SV *tmp; | |
49 | PPCODE: | |
50 | { | |
89ca4ac7 | 51 | dMY_CXT; |
28cd8e1d | 52 | dXSI32; |
89ca4ac7 | 53 | |
72b16652 GS |
54 | /* allow for optional flags argument */ |
55 | if (items > 1) { | |
56 | flags = (int) SvIV(ST(1)); | |
28cd8e1d NC |
57 | } else if (ix) { |
58 | flags = (int) SvIV(get_sv("File::Glob::DEFAULT_FLAGS", GV_ADD)); | |
72b16652 GS |
59 | } |
60 | ||
61 | /* call glob */ | |
62 | retval = bsd_glob(pattern, flags, errfunc, &pglob); | |
63 | GLOB_ERROR = retval; | |
64 | ||
65 | /* return any matches found */ | |
66 | EXTEND(sp, pglob.gl_pathc); | |
67 | for (i = 0; i < pglob.gl_pathc; i++) { | |
68 | /* printf("# bsd_glob: %s\n", pglob.gl_pathv[i]); */ | |
d3d34884 NC |
69 | tmp = newSVpvn_flags(pglob.gl_pathv[i], strlen(pglob.gl_pathv[i]), |
70 | SVs_TEMP); | |
72b16652 GS |
71 | TAINT; |
72 | SvTAINT(tmp); | |
73 | PUSHs(tmp); | |
74 | } | |
75 | ||
76 | bsd_globfree(&pglob); | |
77 | } | |
78 | ||
28cd8e1d NC |
79 | BOOT: |
80 | { | |
81 | CV *cv = newXS("File::Glob::bsd_glob", XS_File__Glob_doglob, __FILE__); | |
82 | XSANY.any_i32 = 1; | |
83 | ||
84 | MY_CXT_INIT; | |
85 | } | |
86 | ||
1cb0fb50 | 87 | INCLUDE: const-xs.inc |