diff options
author | Benjamin Stuhl <sho_pi@hotmail.com> | 2000-11-13 07:08:08 -0800 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2000-11-14 01:21:09 +0000 |
commit | e601c439adce167078ac7b49550c0418ace86f94 (patch) | |
tree | 5cf09c48cc83a16ea460db17f84afc45830116d0 /win32/win32sck.c | |
parent | 0db725d892efd38f45ece17a9db22f98fb713bb3 (diff) | |
download | perl-e601c439adce167078ac7b49550c0418ace86f94.tar.gz |
Get PerlIO building on Win32
Message-ID: <20001113230808.18659.qmail@web6305.mail.yahoo.com>
p4raw-id: //depot/perl@7679
Diffstat (limited to 'win32/win32sck.c')
-rw-r--r-- | win32/win32sck.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/win32/win32sck.c b/win32/win32sck.c index 3b81d8bcae..4a4131c1b1 100644 --- a/win32/win32sck.c +++ b/win32/win32sck.c @@ -418,6 +418,41 @@ win32_socket(int af, int type, int protocol) return s; } +/*
+ * close RTL fd while respecting sockets
+ * added as temporary measure until PerlIO has real
+ * Win32 native layer
+ * -- BKS, 11-11-2000
+*/
+
+int my_close(int fd)
+{
+ int osf;
+ if (!wsock_started) /* No WinSock? */
+ return(close(fd)); /* Then not a socket. */
+ osf = TO_SOCKET(fd);/* Get it now before it's gone! */
+ if (osf != -1) {
+ int err;
+ err = closesocket(osf);
+ if (err == 0) {
+#if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
+ _set_osfhnd(fd, INVALID_HANDLE_VALUE);
+#endif
+ (void)close(fd); /* handle already closed, ignore error */
+ return 0;
+ }
+ else if (err == SOCKET_ERROR) {
+ err = WSAGetLastError();
+ if (err != WSAENOTSOCK) {
+ (void)close(fd);
+ errno = err;
+ return EOF;
+ }
+ }
+ }
+ return close(fd);
+}
+
#undef fclose int my_fclose (FILE *pf) @@ -425,14 +460,14 @@ my_fclose (FILE *pf) int osf; if (!wsock_started) /* No WinSock? */ return(fclose(pf)); /* Then not a socket. */ - osf = TO_SOCKET(fileno(pf));/* Get it now before it's gone! */ + osf = TO_SOCKET(win32_fileno(pf));/* Get it now before it's gone! */
if (osf != -1) { int err; win32_fflush(pf); err = closesocket(osf); if (err == 0) { #if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX) - _set_osfhnd(fileno(pf), INVALID_HANDLE_VALUE); + _set_osfhnd(win32_fileno(pf), INVALID_HANDLE_VALUE);
#endif (void)fclose(pf); /* handle already closed, ignore error */ return 0; |