This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: ithreads doesn't like usedl=n
[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
8063af02 7/* XXX: need some thread awareness */
72b16652
GS
8static int GLOB_ERROR = 0;
9
72f7b9a1 10#include "constants.c"
72b16652
GS
11
12#ifdef WIN32
13#define errfunc NULL
14#else
15int
16errfunc(const char *foo, int bar) {
17 return !(bar == ENOENT || bar == ENOTDIR);
18}
19#endif
20
21MODULE = File::Glob PACKAGE = File::Glob
22
23void
24doglob(pattern,...)
25 char *pattern
e3de7a34 26PROTOTYPE: $;$
72b16652
GS
27PREINIT:
28 glob_t pglob;
29 int i;
30 int retval;
31 int flags = 0;
32 SV *tmp;
33PPCODE:
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 58INCLUDE: constants.xs