diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 2000-12-05 09:14:44 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 2000-12-05 09:14:44 +0000 |
commit | ed59ec62717f0f88ed3d32dff6bf15dd59269b91 (patch) | |
tree | 1f83bba313c5a1a8dec8bd4a1368c4b6f5870361 /win32/win32sck.c | |
parent | 5b3035ed4d02db655cf5d2d62ab1ebb11c131def (diff) | |
download | perl-ed59ec62717f0f88ed3d32dff6bf15dd59269b91.tar.gz |
fix open(FOO, ">&MYSOCK") failure under Windows 9x (problem is
due to the notorious GetFileType() bug in Windows 9x, which fstat()
tickles)
p4raw-id: //depot/perl@7986
Diffstat (limited to 'win32/win32sck.c')
-rw-r--r-- | win32/win32sck.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/win32/win32sck.c b/win32/win32sck.c index b83e0d98f1..d169db6d9e 100644 --- a/win32/win32sck.c +++ b/win32/win32sck.c @@ -485,6 +485,41 @@ my_fclose (FILE *pf) return fclose(pf); } +#undef fstat +int +my_fstat(int fd, struct stat *sbufptr) +{ + /* This fixes a bug in fstat() on Windows 9x. fstat() uses the + * GetFileType() win32 syscall, which will fail on Windows 9x. + * So if we recognize a socket on Windows 9x, we return the + * same results as on Windows NT/2000. + * XXX this should be extended further to set S_IFSOCK on + * sbufptr->st_mode. + */ + int osf; + if (!wsock_started || IsWinNT()) + return fstat(fd, sbufptr); + + osf = TO_SOCKET(fd); + if (osf != -1) { + char sockbuf[256]; + int optlen = sizeof(sockbuf); + int retval; + + retval = getsockopt((SOCKET)osf, SOL_SOCKET, SO_TYPE, sockbuf, &optlen); + if (retval != SOCKET_ERROR || WSAGetLastError() != WSAENOTSOCK) { + sbufptr->st_mode = _S_IFIFO; + sbufptr->st_rdev = sbufptr->st_dev = (dev_t)fd; + sbufptr->st_nlink = 1; + sbufptr->st_uid = sbufptr->st_gid = sbufptr->st_ino = 0; + sbufptr->st_atime = sbufptr->st_mtime = sbufptr->st_ctime = 0; + sbufptr->st_size = (off_t)0; + return 0; + } + } + return fstat(fd, sbufptr); +} + struct hostent * win32_gethostbyaddr(const char *addr, int len, int type) { |