From: Gurusamy Sarathy Date: Thu, 31 Jul 1997 13:26:12 +0000 (+1200) Subject: win32_stat() fixes (2nd try) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=67fbe06e7fe7dfa95ec51821be9237cabdf281e2;p=p5sagit%2Fp5-mst-13.2.git win32_stat() fixes (2nd try) Here's a better version (the earlier one didn't clear the execute bit for some files). This one also enables a test. p5p-msgid: 199708040137.VAA16810@aatma.engin.umich.edu --- diff --git a/t/op/stat.t b/t/op/stat.t index aea5cc1..97f8192 100755 --- a/t/op/stat.t +++ b/t/op/stat.t @@ -75,8 +75,8 @@ if (!$> || ! -w 'Op.stat.tmp') {print "ok 10\n";} else {print "not ok 10\n";} eval '$> = $olduid;'; # switch uid back (may not be implemented) print "# olduid=$olduid, newuid=$>\n" unless ($> == $olduid); -if ($Is_MSWin32 or ! -x 'Op.stat.tmp') {print "ok 11\n";} -else {print "not ok 11\n";} +if (! -x 'Op.stat.tmp') {print "ok 11\n";} +else {print "not ok 11\n";} foreach ((12,13,14,15,16,17)) { print "ok $_\n"; #deleted tests diff --git a/win32/win32.c b/win32/win32.c index 8ec1f9e..ceaca7e 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -514,7 +514,7 @@ opendir(char *filename) /* char *dummy;*/ /* check to see if filename is a directory */ - if(stat(filename, &sbuf) < 0 || sbuf.st_mode & S_IFDIR == 0) { + if (win32_stat(filename, &sbuf) < 0 || sbuf.st_mode & S_IFDIR == 0) { return NULL; } @@ -764,6 +764,7 @@ win32_stat(const char *path, struct stat *buffer) char t[MAX_PATH]; const char *p = path; int l = strlen(path); + int res; if (l > 1) { switch(path[l - 1]) { @@ -776,7 +777,28 @@ win32_stat(const char *path, struct stat *buffer) }; } } - return stat(p, buffer); + res = pIOSubSystem->pfnstat(p,buffer); +#ifdef __BORLANDC__ + if (res == 0) { + if (S_ISDIR(buffer->st_mode)) + buffer->st_mode |= S_IWRITE | S_IEXEC; + else if (S_ISREG(buffer->st_mode)) { + if (l >= 4 && path[l-4] == '.') { + const char *e = path + l - 3; + if (strnicmp(e,"exe",3) + && strnicmp(e,"bat",3) + && strnicmp(e,"com",3) + && (IsWin95() || strnicmp(e,"cmd",3))) + buffer->st_mode &= ~S_IEXEC; + else + buffer->st_mode |= S_IEXEC; + } + else + buffer->st_mode &= ~S_IEXEC; + } + } +#endif + return res; } #ifndef USE_WIN32_RTL_ENV diff --git a/win32/win32iop.h b/win32/win32iop.h index 6ec25b0..56ed402 100644 --- a/win32/win32iop.h +++ b/win32/win32iop.h @@ -138,6 +138,7 @@ void * SetIOSubSystem(void *piosubsystem); #define tmpfile() win32_tmpfile() #define abort() win32_abort() #define fstat(fd,bufptr) win32_fstat(fd,bufptr) +#define stat(pth,bufptr) win32_stat(pth,bufptr) #define setmode(fd,mode) win32_setmode(fd,mode) #define lseek(fd,offset,orig) win32_lseek(fd,offset,orig) #define tell(fd) win32_tell(fd)