# define read PerlLIO_read
# define rename PerlLIO_rename
# define setmode PerlLIO_setmode
-# define stat PerlLIO_stat
+# define stat(buf,sb) PerlLIO_stat(buf,sb)
# define tmpnam PerlLIO_tmpnam
# define umask PerlLIO_umask
# define unlink PerlLIO_unlink
#include <EXTERN.h>
#include <perl.h>
+#include <XSUB.h>
+
#include "bsd_glob.h"
#ifdef I_PWD
# include <pwd.h>
static void qprintf(const char *, Char *);
#endif /* GLOB_DEBUG */
+#ifdef PERL_IMPLICIT_CONTEXT
+static Direntry_t * my_readdir(DIR*);
+
+static Direntry_t *
+my_readdir(DIR *d)
+{
+ return PerlDir_read(d);
+}
+#else
+#define my_readdir readdir
+#endif
+
int
bsd_glob(const char *pattern, int flags,
int (*errfunc)(const char *, int), glob_t *pglob)
if (*pattern == EOS) { /* End of pattern? */
*pathend = EOS;
-#ifdef HAS_LSTAT
if (g_lstat(pathbuf, &sb, pglob))
return(0);
-#endif /* HAS_LSTAT */
if (((pglob->gl_flags & GLOB_MARK) &&
pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
readdirfunc = pglob->gl_readdir;
else
- readdirfunc = readdir;
+ readdirfunc = my_readdir;
while ((dp = (*readdirfunc)(dirp))) {
register U8 *sc;
register Char *dc;
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
(*pglob->gl_closedir)(dirp);
else
- closedir(dirp);
+ PerlDir_close(dirp);
return(err);
}
{
register char **pathv;
register int i;
- Size_t newsize;
char *copy;
const Char *p;
printf("\n");
#endif GLOB_DEBUG
- newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
- pathv = pglob->gl_pathv ?
- realloc((char *)pglob->gl_pathv, newsize) :
- malloc(newsize);
+ if (pglob->gl_pathv)
+ pathv = Renew(pglob->gl_pathv,
+ (2 + pglob->gl_pathc + pglob->gl_offs),char*);
+ else
+ New(0,pathv,(2 + pglob->gl_pathc + pglob->gl_offs),char*);
if (pathv == NULL)
return(GLOB_NOSPACE);
for (p = path; *p++;)
continue;
- if ((copy = malloc(p - path)) != NULL) {
+ New(0, copy, p-path, char);
+ if (copy != NULL) {
g_Ctoc(path, copy);
pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
}
pp = pglob->gl_pathv + pglob->gl_offs;
for (i = pglob->gl_pathc; i--; ++pp)
if (*pp)
- free(*pp);
- free(pglob->gl_pathv);
+ Safefree(*pp);
+ Safefree(pglob->gl_pathv);
}
}
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
return((*pglob->gl_opendir)(buf));
-
- return(opendir(buf));
+ else
+ return(PerlDir_open(buf));
}
-#ifdef HAS_LSTAT
static int
g_lstat(register Char *fn, Stat_t *sb, glob_t *pglob)
{
g_Ctoc(fn, buf);
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
return((*pglob->gl_lstat)(buf, sb));
- return(lstat(buf, sb));
-}
+#ifdef HAS_LSTAT
+ return(PerlLIO_lstat(buf, sb));
+#else
+ return(PerlLIO_stat(buf, sb));
#endif /* HAS_LSTAT */
+}
static int
g_stat(register Char *fn, Stat_t *sb, glob_t *pglob)
g_Ctoc(fn, buf);
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
return((*pglob->gl_stat)(buf, sb));
- return(stat(buf, sb));
+ return(PerlLIO_stat(buf, sb));
}
static Char *
!ENDIF
DYNAMIC_EXT = Socket IO Fcntl Opcode SDBM_File POSIX attrs Thread B re \
- Data/Dumper Devel/Peek ByteLoader Devel/DProf
+ Data/Dumper Devel/Peek ByteLoader Devel/DProf File/Glob
STATIC_EXT = DynaLoader
NONXS_EXT = Errno
PEEK = $(EXTDIR)\Devel\Peek\Peek
BYTELOADER = $(EXTDIR)\ByteLoader\ByteLoader
DPROF = $(EXTDIR)\Devel\DProf\DProf
+GLOB = $(EXTDIR)\File\Glob\Glob
SOCKET_DLL = $(AUTODIR)\Socket\Socket.dll
FCNTL_DLL = $(AUTODIR)\Fcntl\Fcntl.dll
RE_DLL = $(AUTODIR)\re\re.dll
BYTELOADER_DLL = $(AUTODIR)\ByteLoader\ByteLoader.dll
DPROF_DLL = $(AUTODIR)\Devel\DProf\DProf.dll
+GLOB_DLL = $(AUTODIR)\File\Glob\Glob.dll
ERRNO_PM = $(LIBDIR)\Errno.pm
$(PEEK).c \
$(B).c \
$(BYTELOADER).c \
- $(DPROF).c
+ $(DPROF).c \
+ $(GLOB).c
EXTENSION_DLL = \
$(SOCKET_DLL) \
$(RE_DLL) \
$(THREAD_DLL) \
$(BYTELOADER_DLL) \
- $(DPROF_DLL)
+ $(DPROF_DLL) \
+ $(GLOB_DLL)
EXTENSION_PM = \
$(ERRNO_PM)
$(MAKE)
cd ..\..\..\win32
+$(GLOB_DLL): $(PERLEXE) $(GLOB).xs
+ cd $(EXTDIR)\File\$(*B)
+ ..\..\..\miniperl -I..\..\..\lib Makefile.PL INSTALLDIRS=perl
+ $(MAKE)
+ cd ..\..\..\win32
+
$(PEEK_DLL): $(PERLEXE) $(PEEK).xs
cd $(EXTDIR)\Devel\$(*B)
..\..\..\miniperl -I..\..\..\lib Makefile.PL INSTALLDIRS=perl
-del /f $(LIBDIR)\B.pm $(LIBDIR)\O.pm $(LIBDIR)\re.pm
-del /f $(LIBDIR)\Data\Dumper.pm $(LIBDIR)\ByteLoader.pm
-del /f $(LIBDIR)\Devel\Peek.pm $(LIBDIR)\Devel\DProf.pm
+ -del /f $(LIBDIR)\File\Glob.pm
-rmdir /s /q $(LIBDIR)\IO || rmdir /s $(LIBDIR)\IO
-rmdir /s /q $(LIBDIR)\Thread || rmdir /s $(LIBDIR)\Thread
-rmdir /s /q $(LIBDIR)\B || rmdir /s $(LIBDIR)\B
.ENDIF
DYNAMIC_EXT = Socket IO Fcntl Opcode SDBM_File POSIX attrs Thread B re \
- Data/Dumper Devel/Peek ByteLoader Devel/DProf
+ Data/Dumper Devel/Peek ByteLoader Devel/DProf File/Glob
STATIC_EXT = DynaLoader
NONXS_EXT = Errno
PEEK = $(EXTDIR)\Devel\Peek\Peek
BYTELOADER = $(EXTDIR)\ByteLoader\ByteLoader
DPROF = $(EXTDIR)\Devel\DProf\DProf
+GLOB = $(EXTDIR)\File\Glob\Glob
SOCKET_DLL = $(AUTODIR)\Socket\Socket.dll
FCNTL_DLL = $(AUTODIR)\Fcntl\Fcntl.dll
RE_DLL = $(AUTODIR)\re\re.dll
BYTELOADER_DLL = $(AUTODIR)\ByteLoader\ByteLoader.dll
DPROF_DLL = $(AUTODIR)\Devel\DProf\DProf.dll
+GLOB_DLL = $(AUTODIR)\File\Glob\Glob.dll
ERRNO_PM = $(LIBDIR)\Errno.pm
$(PEEK).c \
$(B).c \
$(BYTELOADER).c \
- $(DPROF).c
+ $(DPROF).c \
+ $(GLOB).c
EXTENSION_DLL = \
$(SOCKET_DLL) \
$(RE_DLL) \
$(THREAD_DLL) \
$(BYTELOADER_DLL) \
- $(DPROF_DLL)
+ $(DPROF_DLL) \
+ $(GLOB_DLL)
EXTENSION_PM = \
$(ERRNO_PM)
..\..\..\miniperl -I..\..\..\lib Makefile.PL INSTALLDIRS=perl
cd $(EXTDIR)\Devel\$(*B) && $(MAKE)
+$(GLOB_DLL): $(PERLEXE) $(GLOB).xs
+ cd $(EXTDIR)\File\$(*B) && \
+ ..\..\..\miniperl -I..\..\..\lib Makefile.PL INSTALLDIRS=perl
+ cd $(EXTDIR)\File\$(*B) && $(MAKE)
+
$(PEEK_DLL): $(PERLEXE) $(PEEK).xs
cd $(EXTDIR)\Devel\$(*B) && \
..\..\..\miniperl -I..\..\..\lib Makefile.PL INSTALLDIRS=perl
-del /f $(LIBDIR)\B.pm $(LIBDIR)\O.pm $(LIBDIR)\re.pm
-del /f $(LIBDIR)\Data\Dumper.pm $(LIBDIR)\ByteLoader.pm
-del /f $(LIBDIR)\Devel\Peek.pm $(LIBDIR)\Devel\DProf.pm
+ -del /f $(LIBDIR)\File\Glob.pm
-rmdir /s /q $(LIBDIR)\IO || rmdir /s $(LIBDIR)\IO
-rmdir /s /q $(LIBDIR)\Thread || rmdir /s $(LIBDIR)\Thread
-rmdir /s /q $(LIBDIR)\B || rmdir /s $(LIBDIR)\B