2 Copyright (C) 2008 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 # define WIN32_LEAN_AND_MEAN
24 # include <sys/socket.h>
27 #if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
29 /* Get set_winsock_errno, FD_TO_SOCKET etc. */
33 _gl_close_fd_maybe_socket (int fd)
35 SOCKET sock = FD_TO_SOCKET (fd);
38 ev.lNetworkEvents = 0xDEADBEEF;
39 WSAEnumNetworkEvents (sock, NULL, &ev);
40 if (ev.lNetworkEvents != 0xDEADBEEF)
42 /* FIXME: other applications, like squid, use an undocumented
43 _free_osfhnd free function. But this is not enough: The 'osfile'
44 flags for fd also needs to be cleared, but it is hard to access it.
45 Instead, here we just close twice the file descriptor. */
46 if (closesocket (sock))
53 /* This call frees the file descriptor and does a
54 CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails. */
64 /* Override close() to call into other gnulib modules. */
70 #if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
71 int retval = _gl_close_fd_maybe_socket (fd);
73 int retval = close (fd);
76 #ifdef FCHDIR_REPLACEMENT
78 _gl_unregister_fd (fd);