summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>2000-12-05 09:14:44 +0000
committerGurusamy Sarathy <gsar@cpan.org>2000-12-05 09:14:44 +0000
commited59ec62717f0f88ed3d32dff6bf15dd59269b91 (patch)
tree1f83bba313c5a1a8dec8bd4a1368c4b6f5870361 /win32
parent5b3035ed4d02db655cf5d2d62ab1ebb11c131def (diff)
downloadperl-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')
-rw-r--r--win32/win32.c2
-rw-r--r--win32/win32.h1
-rw-r--r--win32/win32sck.c35
3 files changed, 37 insertions, 1 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 2167eeb9a1..924ee92a7e 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -2350,7 +2350,7 @@ win32_fstat(int fd,struct stat *sbufptr)
}
return rc;
#else
- return fstat(fd,sbufptr);
+ return my_fstat(fd,sbufptr);
#endif
}
diff --git a/win32/win32.h b/win32/win32.h
index 1640564a65..1040ef1c1a 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -344,6 +344,7 @@ DllExport void win32_get_child_IO(child_IO_table* ptr);
extern FILE * my_fdopen(int, char *);
#endif
extern int my_fclose(FILE *);
+extern int my_fstat(int fd, struct stat *sbufptr);
extern int do_aspawn(void *really, void **mark, void **sp);
extern int do_spawn(char *cmd);
extern int do_spawn_nowait(char *cmd);
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)
{