Skip to content

Commit da8f500

Browse files
authored
Make Windows fcntl() and lseek() fixes (#668)
* F_SETFD should always return 0 on success * F_SETFL is not implemented on nt * nt lseek, error with ESPIPE when attempting on socket
1 parent ef97767 commit da8f500

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

libc/calls/fcntl-nt.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ textwindows int sys_fcntl_nt(int fd, int cmd, uintptr_t arg) {
320320
// O_DSYNC / O_RSYNC / O_SYNC maybe if we fsync() everything
321321
// O_DIRECT | O_RANDOM | O_SEQUENTIAL | O_NDELAY possible but
322322
// not worth it.
323-
rc = einval();
323+
rc = enosys();
324324
} else if (cmd == F_GETFD) {
325325
if (g_fds.p[fd].flags & O_CLOEXEC) {
326326
rc = FD_CLOEXEC;
@@ -330,11 +330,10 @@ textwindows int sys_fcntl_nt(int fd, int cmd, uintptr_t arg) {
330330
} else if (cmd == F_SETFD) {
331331
if (arg & FD_CLOEXEC) {
332332
g_fds.p[fd].flags |= O_CLOEXEC;
333-
rc = FD_CLOEXEC;
334333
} else {
335334
g_fds.p[fd].flags &= ~O_CLOEXEC;
336-
rc = 0;
337335
}
336+
rc = 0;
338337
} else if (cmd == F_SETLK || cmd == F_SETLKW || cmd == F_GETLK) {
339338
pthread_mutex_lock(&g_locks.mu);
340339
rc = sys_fcntl_nt_lock(g_fds.p + fd, fd, cmd, arg);

libc/calls/lseek-nt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ textwindows int64_t sys_lseek_nt(int fd, int64_t offset, int whence) {
3434
} else {
3535
return espipe();
3636
}
37+
} else if (__isfdkind(fd, kFdSocket)) {
38+
return espipe();
3739
} else {
3840
return ebadf();
3941
}

0 commit comments

Comments
 (0)