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