1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "bsd_glob.h"
#define MY_CXT_KEY "File::Glob::_guts" XS_VERSION
typedef struct {
int x_GLOB_ERROR;
} my_cxt_t;
START_MY_CXT
#define GLOB_ERROR (MY_CXT.x_GLOB_ERROR)
#include "const-c.inc"
#ifdef WIN32
#define errfunc NULL
#else
static int
errfunc(const char *foo, int bar) {
PERL_UNUSED_ARG(foo);
return !(bar == EACCES || bar == ENOENT || bar == ENOTDIR);
}
#endif
MODULE = File::Glob PACKAGE = File::Glob
int
GLOB_ERROR()
PREINIT:
dMY_CXT;
CODE:
RETVAL = GLOB_ERROR;
OUTPUT:
RETVAL
void
doglob(pattern,...)
char *pattern
PROTOTYPE: $;$
PREINIT:
glob_t pglob;
int i;
int retval;
int flags = 0;
SV *tmp;
PPCODE:
{
dMY_CXT;
dXSI32;
/* allow for optional flags argument */
if (items > 1) {
flags = (int) SvIV(ST(1));
/* remove unsupported flags */
flags &= ~(GLOB_APPEND | GLOB_DOOFFS | GLOB_ALTDIRFUNC | GLOB_MAGCHAR);
} else if (ix) {
flags = (int) SvIV(get_sv("File::Glob::DEFAULT_FLAGS", GV_ADD));
}
/* call glob */
bzero(&pglob, sizeof(glob_t));
retval = bsd_glob(pattern, flags, errfunc, &pglob);
GLOB_ERROR = retval;
/* return any matches found */
EXTEND(sp, pglob.gl_pathc);
for (i = 0; i < pglob.gl_pathc; i++) {
/* printf("# bsd_glob: %s\n", pglob.gl_pathv[i]); */
tmp = newSVpvn_flags(pglob.gl_pathv[i], strlen(pglob.gl_pathv[i]),
SVs_TEMP);
TAINT;
SvTAINT(tmp);
PUSHs(tmp);
}
bsd_globfree(&pglob);
}
BOOT:
{
CV *cv = newXS("File::Glob::bsd_glob", XS_File__Glob_doglob, __FILE__);
XSANY.any_i32 = 1;
}
BOOT:
{
MY_CXT_INIT;
}
INCLUDE: const-xs.inc
|