- fd = _open(fname, oflag, create_permission);
- return fd;
-}
-/*
- * Open a file for reading, return its handle.
- * This can be used in place of open() when a handle is desired for
- * waiting on it with WaitForMultipleObjects() or similar.
- * Ensure the handle is not zero in order to prevent a problem
- * input_fd.
- */
-int
-w32_openhandle(const char *fname, int oflag)
-{
- HANDLE handle;
-
- handle = CreateFile(fname, GENERIC_READ, FILE_SHARE_READ, NULL,
- OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-
- if (handle == INVALID_HANDLE_VALUE) {
- errno = GetLastError();
- return -1;
- }
- if (handle == 0) {
- HANDLE dup_handle;
- if (!DuplicateHandle(GetCurrentProcess(), handle,
- GetCurrentProcess(), &dup_handle,
- 0, FALSE, DUPLICATE_SAME_ACCESS)) {
- errno = GetLastError();
+ if (fd_is_socket(fd, &sock)) {
+ if (closesocket(sock)) {
+ w32_set_winsock_errno();