fcntl: fix F_SETFD and F_GETFD

This commit is contained in:
Matheus
2024-06-22 19:28:43 -03:00
parent bac3dde23e
commit 8bda483d64
+4 -2
View File
@@ -10,6 +10,8 @@
#define F_GETFL 3 #define F_GETFL 3
#define F_SETFL 4 #define F_SETFL 4
#define FD_CLOEXEC 1
syscallret_t syscall_fcntl(context_t *, int fd, int cmd, uint64_t arg) { syscallret_t syscall_fcntl(context_t *, int fd, int cmd, uint64_t arg) {
syscallret_t ret = { syscallret_t ret = {
.ret = -1 .ret = -1
@@ -42,13 +44,13 @@ syscallret_t syscall_fcntl(context_t *, int fd, int cmd, uint64_t arg) {
FILE_UNLOCK(file); FILE_UNLOCK(file);
break; break;
case F_SETFD: case F_SETFD:
ret.errno = fd_setflags(fd, arg); ret.errno = fd_setflags(fd, (arg & FD_CLOEXEC) ? O_CLOEXEC : 0);
ret.ret = 0; ret.ret = 0;
break; break;
case F_GETFD: case F_GETFD:
int flg; int flg;
ret.errno = fd_getflags(fd, &flg); ret.errno = fd_getflags(fd, &flg);
ret.ret = flg; ret.ret = flg ? FD_CLOEXEC : 0;
break; break;
default: default:
ret.errno = EINVAL; ret.errno = EINVAL;