hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 591bc229a525f211037c00ab6004fe945ee78f17
parent 1228d3bf612bfe4cba70e1e7786617cdf1c58a31
Author: Curtis Arthaud <uku82@gmx.fr>
Date:   Sat,  6 Apr 2024 15:13:13 +0200

syscalls: add utimensat, futimens

Signed-off-by: Curtis Arthaud <uku82@gmx.fr>

Diffstat:
Mrt/+freebsd/syscalls.ha | 11+++++++++++
Mrt/+freebsd/types.ha | 2++
Mrt/+linux/syscalls.ha | 11+++++++++++
Mrt/+linux/types.ha | 2++
Mrt/+openbsd/syscalls.ha | 33+++++++++++++++++++++++++++++++++
Mrt/+openbsd/types.ha | 2++
6 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/rt/+freebsd/syscalls.ha b/rt/+freebsd/syscalls.ha @@ -203,6 +203,17 @@ export fn fchownat(dirfd: int, path: path, uid: uint, gid: uint, flags: int) (vo dirfd: u64, path: uintptr: u64, uid: u32, gid: u32, flags: u64))?; }; +export fn utimensat(dirfd: int, path: str, ts: *[2]timespec, flags: int) (void | errno) = { + let path = kpath(path)?; + wrap_return(syscall4(SYS_utimensat, + dirfd: u64, path: uintptr: u64, ts: uintptr: u64, flags: u64))?; +}; + +export fn futimens(fd: int, ts: *[2]timespec) (void | errno) = { + wrap_return(syscall2(SYS_futimens, + fd: u64, ts: uintptr: u64))?; +}; + export fn faccessat( dirfd: int, path: path, diff --git a/rt/+freebsd/types.ha b/rt/+freebsd/types.ha @@ -74,6 +74,8 @@ export type timespec = struct { tv_nsec: i64, }; +export def UTIME_OMIT = -0x2; + export type timeval = struct { tv_sec: time_t, tv_usec: suseconds_t, diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -177,6 +177,17 @@ export fn fchownat(dirfd: int, path: path, uid: uint, gid: uint, flags: int) (vo dirfd: u64, path: uintptr: u64, uid: u32, gid: u32, flags: u64))?; }; +export fn utimensat(dirfd: int, path: str, ts: *[2]timespec, flags: int) (void | errno) = { + let path = kpath(path)?; + wrap_return(syscall4(SYS_utimensat, + dirfd: u64, path: uintptr: u64, ts: uintptr: u64, flags: u64))?; +}; + +export fn futimens(fd: int, ts: *[2]timespec) (void | errno) = { + wrap_return(syscall4(SYS_utimensat, + fd: u64, 0, ts: uintptr: u64, 0))?; +}; + export fn renameat( olddirfd: int, oldpath: path, diff --git a/rt/+linux/types.ha b/rt/+linux/types.ha @@ -35,6 +35,8 @@ export type timespec = struct { tv_nsec: i64, }; +export def UTIME_OMIT = 0x3ffffffe; + export type itimerspec = struct { it_interval: timespec, it_value: timespec, diff --git a/rt/+openbsd/syscalls.ha b/rt/+openbsd/syscalls.ha @@ -581,7 +581,40 @@ export fn setpgid(pid: pid_t, pgrp: pid_t) (void | errno) = { // futex // utimensat + +@symbol("utimensat") fn libc_utimensat( + fd: int, + path: *const u8, + times: *const [2]timespec, + flag: int +) int; + +export fn utimensat( + dirfd: int, + path: str, + ts: *[2]timespec, + flags: int +) (void | errno) = { + let res = libc_utimensat(dirfd, cpath(path)?, ts, flags); + if (res == -1) { + return *__errno(): errno; + }; +}; + // futimens + +@symbol("futimens") fn libc_futimens( + fd: int, + times: *const [2]timespec +) int; + +export fn futimens(fd: int, ts: *[2]timespec) (void | errno) = { + let res = libc_futimens(fd, ts); + if (res == -1) { + return *__errno(): errno; + }; +}; + // kbind // clock_gettime diff --git a/rt/+openbsd/types.ha b/rt/+openbsd/types.ha @@ -177,6 +177,8 @@ export type timespec = struct { tv_nsec: i64, }; +export def UTIME_OMIT = -0x1; + export def CLOCK_REALTIME: clockid_t = 0; export def CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2; export def CLOCK_MONOTONIC: clockid_t = 3;