This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Nothing autoloaded in Sys::Hostname or I18N::Langinfo, so don't use AutoLoader;
[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
89ca4ac7
JH
30BOOT:
31{
32 MY_CXT_INIT;
33}
34
72b16652
GS
35void
36doglob(pattern,...)
37 char *pattern
e3de7a34 38PROTOTYPE: $;$
72b16652
GS
39PREINIT:
40 glob_t pglob;
41 int i;
42 int retval;
43 int flags = 0;
44 SV *tmp;
45PPCODE:
46 {
89ca4ac7
JH
47 dMY_CXT;
48
72b16652
GS
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]); */
d3d34884
NC
62 tmp = newSVpvn_flags(pglob.gl_pathv[i], strlen(pglob.gl_pathv[i]),
63 SVs_TEMP);
72b16652
GS
64 TAINT;
65 SvTAINT(tmp);
66 PUSHs(tmp);
67 }
68
69 bsd_globfree(&pglob);
70 }
71
1cb0fb50 72INCLUDE: const-xs.inc