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