diff --git a/mod.zig b/mod.zig index 4dd50378701f66b4c3c1bba6a5892f72a8f9f401..7b47d580bf20bd7b27f859614f6e42deb7af656b 100644 --- a/mod.zig +++ b/mod.zig @@ -2750,6 +2750,7 @@ pub const libc = struct { pub extern fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) c_int; pub extern fn sched_getaffinity(pid: pid_t, cpusetsize: usize, mask: *cpu_set_t) c_int; pub extern fn getrandom(buf: [*]u8, size: usize, flags: c_uint) isize; + pub extern fn flock(fd: c_int, op: c_int) c_int; }; pub const clock_t = c_long; @@ -3206,6 +3207,13 @@ pub const GRND = struct { pub const INSECURE = 0x0004; }; +pub const LOCK = struct { + pub const SH = 1; + pub const EX = 2; + pub const NB = 4; + pub const UN = 8; +}; + pub fn getpid() pid_t { return libc.getpid(); } @@ -3499,3 +3507,8 @@ pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 { std.debug.assert(rc >= 0); return buf[0..@intCast(rc)]; } +pub fn flock(fd: c_int, op: c_int) !void { + const rc = libc.flock(fd, op); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + std.debug.assert(rc == 0); +} diff --git a/test.zig b/test.zig index 29f1b12d7d8c3d043f263927d3267c725cb3d1b6..63a51d0f57fd78244ee29e29e3c8e290a41854d7 100644 --- a/test.zig +++ b/test.zig @@ -60,4 +60,5 @@ test { _ = &linux.pthread_cond_broadcast; _ = &linux.mkdtemp; _ = &linux.getrandom; + _ = &linux.flock; }