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 {
27502750 pub extern fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) c_int;
27512751 pub extern fn sched_getaffinity(pid: pid_t, cpusetsize: usize, mask: *cpu_set_t) c_int;
27522752 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;
27532754};
27542755
27552756pub const clock_t = c_long;
......@@ -3206,6 +3207,13 @@ pub const GRND = struct {
32063207 pub const INSECURE = 0x0004;
32073208};
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
32093217pub fn getpid() pid_t {
32103218 return libc.getpid();
32113219}
......@@ -3499,3 +3507,8 @@ pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 {
34993507 std.debug.assert(rc >= 0);
35003508 return buf[0..@intCast(rc)];
35013509}
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 {
6060 _ = &linux.pthread_cond_broadcast;
6161 _ = &linux.mkdtemp;
6262 _ = &linux.getrandom;
63 _ = &linux.flock;
6364}