Commit | Line | Data |
72b16652 |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
4 | |
5 | #include "bsd_glob.h" |
6 | |
8063af02 |
7 | /* XXX: need some thread awareness */ |
72b16652 |
8 | static int GLOB_ERROR = 0; |
9 | |
72f7b9a1 |
10 | #include "constants.c" |
72b16652 |
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 |
e3de7a34 |
26 | PROTOTYPE: $;$ |
72b16652 |
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 | |
72f7b9a1 |
58 | INCLUDE: constants.xs |