kernel+libc: Add F_GETFD, F_SETFD, F_GETFL and F_SETFL to fcntl

This commit is contained in:
apio 2023-03-28 20:55:38 +02:00
parent df10544e84
commit 6239ed83c7
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 27 additions and 0 deletions

View File

@ -113,6 +113,25 @@ Result<u64> sys_fcntl(Registers*, SyscallArgs args)
return (u64)new_fd;
}
case F_GETFD: return (u64) !!(descriptor.flags & O_CLOEXEC);
case F_SETFD: {
int arg = (int)args[2];
if (arg == FD_CLOEXEC) descriptor.flags |= O_CLOEXEC;
else
descriptor.flags &= ~O_CLOEXEC;
return 0;
}
case F_GETFL: return (u64)(descriptor.flags & ~O_CLOEXEC);
case F_SETFL: {
int arg = (int)args[2];
descriptor.flags &= ~(O_APPEND | O_NONBLOCK);
arg &= (O_APPEND | O_NONBLOCK);
descriptor.flags |= arg;
return 0;
}
default: return err(EINVAL);
}
}

View File

@ -5,5 +5,11 @@
#define F_DUPFD 0
#define F_DUPFD_CLOEXEC 1
#define F_GETFD 2
#define F_SETFD 3
#define F_SETFL 4
#define F_GETFL 5
#define FD_CLOEXEC 1
#endif

View File

@ -13,4 +13,6 @@
#define O_NONBLOCK 64
#define O_CLOEXEC 128
#define O_ACCMODE O_RDWR
#endif