commit a0d9ef9d5132a1338dcfa6848f88e523517ec2c3
parent 5cdb439923a9f00cb0efc994dd55ab914194a2fa
Author: Drew DeVault <sir@cmpwn.com>
Date: Mon, 8 Feb 2021 18:13:06 -0500
rt: add fcntl wrapper
Diffstat:
2 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha
@@ -153,3 +153,19 @@ export fn faccessat(
export fn access(path: *const char, mode: int) (bool | errno) =
faccessat(AT_FDCWD, path, mode, 0);
+
+export type fcntl_arg = (void | int | *st_flock | *f_owner_ex | *u64);
+
+export fn fcntl(fd: int, cmd: int, arg: fcntl_arg) (int | errno) = {
+ let _fd = fd: u64, _cmd = cmd: u64;
+ return match (wrap_return(match (arg) {
+ void => syscall2(SYS_fcntl, _fd, _cmd),
+ i: int => syscall3(SYS_fcntl, _fd, _cmd, i: u64),
+ l: *st_flock => syscall3(SYS_fcntl, _fd, _cmd, l: uintptr: u64),
+ o: *f_owner_ex => syscall3(SYS_fcntl, _fd, _cmd, o: uintptr: u64),
+ u: *u64 => syscall3(SYS_fcntl, _fd, _cmd, u: uintptr: u64),
+ })) {
+ err: errno => err,
+ n: u64 => n: int,
+ };
+};
diff --git a/rt/+linux/types.ha b/rt/+linux/types.ha
@@ -175,3 +175,32 @@ export def F_OK: int = 0;
export def R_OK: int = 4;
export def W_OK: int = 2;
export def X_OK: int = 1;
+
+export def F_DUPFD: int = 0;
+export def F_GETFD: int = 1;
+export def F_SETFD: int = 2;
+export def F_GETFL: int = 3;
+export def F_SETFL: int = 4;
+export def F_SETOWN: int = 8;
+export def F_GETOWN: int = 9;
+export def F_SETSIG: int = 10;
+export def F_GETSIG: int = 11;
+export def F_GETLK: int = 12;
+export def F_SETLK: int = 13;
+export def F_SETLKW: int = 14;
+export def F_SETOWN_EX: int = 15;
+export def F_GETOWN_EX: int = 16;
+export def F_GETOWNER_UIDS: int = 17;
+
+export type st_flock = struct {
+ l_type: i16,
+ l_whence: i16,
+ l_start: i64,
+ l_len: i64,
+ pid: int,
+};
+
+export type f_owner_ex = struct {
+ _type: int,
+ pid: int,
+};