From: Vadim Konovalov Date: Mon, 16 Oct 2000 09:55:03 +0000 (+0400) Subject: Borland C fstat() never saw the fd as writable. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2a07f407e1463660d7c00682ec168da23d057171;p=p5sagit%2Fp5-mst-13.2.git Borland C fstat() never saw the fd as writable. Subject: fix for Borland's weak "stat" (perl@7211) From: "Konovalov, Vadim" Message-ID: <402099F49BEED211999700805FC7359F7C0E40@ru0028exch01.spb.lucent.com> p4raw-id: //depot/perl@7362 --- diff --git a/win32/win32.c b/win32/win32.c index 0e4c2e0..2b31878 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2312,7 +2312,25 @@ win32_abort(void) DllExport int win32_fstat(int fd,struct stat *sbufptr) { +#ifdef __BORLANDC__ + /* A file designated by filehandle is not shown as accessible + * for write operations, probably because it is opened for reading. + * --Vadim Konovalov + */ + int rc = fstat(fd,sbufptr); + BY_HANDLE_FILE_INFORMATION bhfi; + if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &bhfi)) { + sbufptr->st_mode &= 0xFE00; + if (bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY) + sbufptr->st_mode |= (S_IREAD + (S_IREAD >> 3) + (S_IREAD >> 6)); + else + sbufptr->st_mode |= ((S_IREAD|S_IWRITE) + ((S_IREAD|S_IWRITE) >> 3) + + ((S_IREAD|S_IWRITE) >> 6)); + } + return rc; +#else return fstat(fd,sbufptr); +#endif } DllExport int