From: Gurusamy Sarathy Date: Thu, 14 Oct 1999 03:49:54 +0000 (+0000) Subject: File::Glob fixes for Windows X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4f49e16e1f424d2d3ef7213c0dc56e638eb789a6;p=p5sagit%2Fp5-mst-13.2.git File::Glob fixes for Windows p4raw-id: //depot/perl@4373 --- diff --git a/XSUB.h b/XSUB.h index 5ce8fb4..ae746a6 100644 --- a/XSUB.h +++ b/XSUB.h @@ -203,7 +203,7 @@ # 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 diff --git a/ext/File/Glob/bsd_glob.c b/ext/File/Glob/bsd_glob.c index 38ace47..15b1a6d 100644 --- a/ext/File/Glob/bsd_glob.c +++ b/ext/File/Glob/bsd_glob.c @@ -71,6 +71,8 @@ static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; #include #include +#include + #include "bsd_glob.h" #ifdef I_PWD # include @@ -161,6 +163,18 @@ static int match(Char *, Char *, Char *); 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) @@ -534,10 +548,8 @@ glob2(Char *pathbuf, Char *pathend, Char *pattern, 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) @@ -611,7 +623,7 @@ glob3(Char *pathbuf, Char *pathend, Char *pattern, 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; @@ -634,7 +646,7 @@ glob3(Char *pathbuf, Char *pathend, Char *pattern, if (pglob->gl_flags & GLOB_ALTDIRFUNC) (*pglob->gl_closedir)(dirp); else - closedir(dirp); + PerlDir_close(dirp); return(err); } @@ -658,7 +670,6 @@ globextend(const Char *path, glob_t *pglob) { register char **pathv; register int i; - Size_t newsize; char *copy; const Char *p; @@ -669,10 +680,11 @@ globextend(const Char *path, glob_t *pglob) 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); @@ -686,7 +698,8 @@ globextend(const Char *path, glob_t *pglob) 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; } @@ -756,8 +769,8 @@ bsd_globfree(glob_t *pglob) 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); } } @@ -773,11 +786,10 @@ g_opendir(register Char *str, glob_t *pglob) 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) { @@ -786,9 +798,12 @@ 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) @@ -798,7 +813,7 @@ 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 * diff --git a/win32/Makefile b/win32/Makefile index 57e9d44..def59fc 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -546,7 +546,7 @@ SETARGV_OBJ = setargv$(o) !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 @@ -566,6 +566,7 @@ ERRNO = $(EXTDIR)\Errno\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 @@ -581,6 +582,7 @@ PEEK_DLL = $(AUTODIR)\Devel\Peek\Peek.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 @@ -598,7 +600,8 @@ EXTENSION_C = \ $(PEEK).c \ $(B).c \ $(BYTELOADER).c \ - $(DPROF).c + $(DPROF).c \ + $(GLOB).c EXTENSION_DLL = \ $(SOCKET_DLL) \ @@ -614,7 +617,8 @@ EXTENSION_DLL = \ $(RE_DLL) \ $(THREAD_DLL) \ $(BYTELOADER_DLL) \ - $(DPROF_DLL) + $(DPROF_DLL) \ + $(GLOB_DLL) EXTENSION_PM = \ $(ERRNO_PM) @@ -823,6 +827,12 @@ $(DPROF_DLL): $(PERLEXE) $(DPROF).xs $(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 @@ -929,6 +939,7 @@ distclean: clean -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 diff --git a/win32/makefile.mk b/win32/makefile.mk index ceb5be0..a9d6983 100644 --- a/win32/makefile.mk +++ b/win32/makefile.mk @@ -663,7 +663,7 @@ SETARGV_OBJ = setargv$(o) .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 @@ -683,6 +683,7 @@ ERRNO = $(EXTDIR)\Errno\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 @@ -698,6 +699,7 @@ PEEK_DLL = $(AUTODIR)\Devel\Peek\Peek.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 @@ -715,7 +717,8 @@ EXTENSION_C = \ $(PEEK).c \ $(B).c \ $(BYTELOADER).c \ - $(DPROF).c + $(DPROF).c \ + $(GLOB).c EXTENSION_DLL = \ $(SOCKET_DLL) \ @@ -731,7 +734,8 @@ EXTENSION_DLL = \ $(RE_DLL) \ $(THREAD_DLL) \ $(BYTELOADER_DLL) \ - $(DPROF_DLL) + $(DPROF_DLL) \ + $(GLOB_DLL) EXTENSION_PM = \ $(ERRNO_PM) @@ -1005,6 +1009,11 @@ $(DPROF_DLL): $(PERLEXE) $(DPROF).xs ..\..\..\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 @@ -1095,6 +1104,7 @@ distclean: clean -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