Example #1
0
int
my_fclose (FILE *pf)
{
    int osf;
    if (!wsock_started)		/* No WinSock? */
	return(fclose(pf));	/* Then not a socket. */
    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(win32_fileno(pf), INVALID_HANDLE_VALUE);
#endif
	    (void)fclose(pf);	/* handle already closed, ignore error */
	    return 0;
	}
	else if (err == SOCKET_ERROR) {
	    err = WSAGetLastError();
	    if (err != WSAENOTSOCK) {
		(void)fclose(pf);
		errno = err;
		return EOF;
	    }
	}
    }
    return fclose(pf);
}
Example #2
0
int
my_fclose (FILE *pf)
{
    int osf;
    if (!wsock_started)		/* No WinSock? */
        return(fclose(pf));	/* Then not a socket. */
    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) {
            assert(_osfhnd(win32_fileno(pf)) == osf); /* catch a bad ioinfo struct def */
            /* don't close freed handle */
            _set_osfhnd(win32_fileno(pf), INVALID_HANDLE_VALUE);
            return fclose(pf);
        }
        else if (err == SOCKET_ERROR) {
            err = get_last_socket_error();
            if (err != ENOTSOCK) {
                (void)fclose(pf);
                errno = err;
                return EOF;
            }
        }
    }
    return fclose(pf);
}