authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-06 03:00:45 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-06 03:00:45 -07:00
log65fa94b4a49f1d5d31ecebc7130e05ec0c2802bf
tree4db1071d5d989db626664dc40db414675fd40221
parentea93df8f7bcd07e2c5a74b7d17e03b12ae659dd7
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add flock


2 files changed, 14 insertions(+), 0 deletions(-)

mod.zig+13
...@@ -2750,6 +2750,7 @@ pub const libc = struct {...@@ -2750,6 +2750,7 @@ pub const libc = struct {
2750 pub extern fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) c_int;2750 pub extern fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) c_int;
2751 pub extern fn sched_getaffinity(pid: pid_t, cpusetsize: usize, mask: *cpu_set_t) c_int;2751 pub extern fn sched_getaffinity(pid: pid_t, cpusetsize: usize, mask: *cpu_set_t) c_int;
2752 pub extern fn getrandom(buf: [*]u8, size: usize, flags: c_uint) isize;2752 pub extern fn getrandom(buf: [*]u8, size: usize, flags: c_uint) isize;
2753 pub extern fn flock(fd: c_int, op: c_int) c_int;
2753};2754};
27542755
2755pub const clock_t = c_long;2756pub const clock_t = c_long;
...@@ -3206,6 +3207,13 @@ pub const GRND = struct {...@@ -3206,6 +3207,13 @@ pub const GRND = struct {
3206 pub const INSECURE = 0x0004;3207 pub const INSECURE = 0x0004;
3207};3208};
32083209
3210pub const LOCK = struct {
3211 pub const SH = 1;
3212 pub const EX = 2;
3213 pub const NB = 4;
3214 pub const UN = 8;
3215};
3216
3209pub fn getpid() pid_t {3217pub fn getpid() pid_t {
3210 return libc.getpid();3218 return libc.getpid();
3211}3219}
...@@ -3499,3 +3507,8 @@ pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 {...@@ -3499,3 +3507,8 @@ pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 {
3499 std.debug.assert(rc >= 0);3507 std.debug.assert(rc >= 0);
3500 return buf[0..@intCast(rc)];3508 return buf[0..@intCast(rc)];
3501}3509}
3510pub fn flock(fd: c_int, op: c_int) !void {
3511 const rc = libc.flock(fd, op);
3512 if (rc == -1) return errno.fromInt(errno.fromLibC());
3513 std.debug.assert(rc == 0);
3514}
test.zig+1
...@@ -60,4 +60,5 @@ test {...@@ -60,4 +60,5 @@ test {
60 _ = &linux.pthread_cond_broadcast;60 _ = &linux.pthread_cond_broadcast;
61 _ = &linux.mkdtemp;61 _ = &linux.mkdtemp;
62 _ = &linux.getrandom;62 _ = &linux.getrandom;
63 _ = &linux.flock;
63}64}