Revert "Revert "Mention the unit of time""
[p5sagit/p5-mst-13.2.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 #define MY_CXT_KEY "File::Glob::_guts" XS_VERSION
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)
16
17 #include "const-c.inc"
18
19 #ifdef WIN32
20 #define errfunc         NULL
21 #else
22 static int
23 errfunc(const char *foo, int bar) {
24   return !(bar == EACCES || bar == ENOENT || bar == ENOTDIR);
25 }
26 #endif
27
28 MODULE = File::Glob             PACKAGE = File::Glob
29
30 BOOT:
31 {
32     MY_CXT_INIT;
33 }
34
35 void
36 doglob(pattern,...)
37     char *pattern
38 PROTOTYPE: $;$
39 PREINIT:
40     glob_t pglob;
41     int i;
42     int retval;
43     int flags = 0;
44     SV *tmp;
45 PPCODE:
46     {
47         dMY_CXT;
48
49         /* allow for optional flags argument */
50         if (items > 1) {
51             flags = (int) SvIV(ST(1));
52         }
53
54         /* call glob */
55         retval = bsd_glob(pattern, flags, errfunc, &pglob);
56         GLOB_ERROR = retval;
57
58         /* return any matches found */
59         EXTEND(sp, pglob.gl_pathc);
60         for (i = 0; i < pglob.gl_pathc; i++) {
61             /* printf("# bsd_glob: %s\n", pglob.gl_pathv[i]); */
62             tmp = sv_2mortal(newSVpvn(pglob.gl_pathv[i],
63                                       strlen(pglob.gl_pathv[i])));
64             TAINT;
65             SvTAINT(tmp);
66             PUSHs(tmp);
67         }
68
69         bsd_globfree(&pglob);
70     }
71
72 INCLUDE: const-xs.inc