This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Merge B::BM::PREVIOUS, B::BM::RARE and B::BM::USEFUL into the common accessor.
[perl5.git] / ext / File-Glob / Glob.xs
CommitLineData
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
9typedef struct {
10 int x_GLOB_ERROR;
11} my_cxt_t;
12
13START_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 22static int
72b16652 23errfunc(const char *foo, int bar) {
5f18268b 24 return !(bar == EACCES || bar == ENOENT || bar == ENOTDIR);
72b16652
GS
25}
26#endif
27
28MODULE = File::Glob PACKAGE = File::Glob
29
b84cd0b1
NC
30int
31GLOB_ERROR()
32 PREINIT:
33 dMY_CXT;
34 CODE:
35 RETVAL = GLOB_ERROR;
36 OUTPUT:
37 RETVAL
38
72b16652
GS
39void
40doglob(pattern,...)
41 char *pattern
e3de7a34 42PROTOTYPE: $;$
72b16652
GS
43PREINIT:
44 glob_t pglob;
45 int i;
46 int retval;
47 int flags = 0;
48 SV *tmp;
49PPCODE:
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
79BOOT:
80{
81 CV *cv = newXS("File::Glob::bsd_glob", XS_File__Glob_doglob, __FILE__);
82 XSANY.any_i32 = 1;
bcd258b8 83}
28cd8e1d 84
bcd258b8
NC
85BOOT:
86{
28cd8e1d
NC
87 MY_CXT_INIT;
88}
89
1cb0fb50 90INCLUDE: const-xs.inc