From 613956cc47c2513cdd27d57e5eb2fa36a368c21b Mon Sep 17 00:00:00 2001 From: LeRoyce Pearson Date: Tue, 17 Mar 2020 21:02:19 -0600 Subject: [PATCH] Remove `fcntlFlock` and replace with plain `fcntl` --- lib/std/fs.zig | 4 ++-- lib/std/os.zig | 13 +------------ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index dd25b29042..7452dd0e0e 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -688,7 +688,7 @@ pub const Dir = struct { flock.l_start = 0; flock.l_len = 0; flock.l_pid = 0; - try os.fcntlFlock(fd, .SetLockBlocking, &flock); + try os.fcntl(fd, os.F_SETLKW, &flock); locked = true; } @@ -754,7 +754,7 @@ pub const Dir = struct { flock.l_start = 0; flock.l_len = 0; flock.l_pid = 0; - try os.fcntlFlock(fd, .SetLockBlocking, &flock); + try os.fcntl(fd, os.F_SETLKW, &flock); } return File{ .handle = fd, .io_mode = .blocking }; diff --git a/lib/std/os.zig b/lib/std/os.zig index 2741d2d8f3..f6fdb9482f 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -1140,24 +1140,13 @@ pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*:0]u8) allocator.free(envp_buf); } -pub const LockCmd = enum { - GetLock, - SetLock, - SetLockBlocking, -}; - pub const FcntlError = error{ /// The file is locked by another process FileLocked, } || UnexpectedError; /// Attempts to get lock the file, blocking if the file is locked. -pub fn fcntlFlock(fd: fd_t, lock_cmd: LockCmd, flock_p: *Flock) FcntlError!void { - const cmd: i32 = switch (lock_cmd) { - .GetLock => F_GETLK, - .SetLock => F_SETLK, - .SetLockBlocking => F_SETLKW, - }; +pub fn fcntl(fd: fd_t, cmd: i32, flock_p: *Flock) FcntlError!void { while (true) { switch (errno(system.fcntl(fd, cmd, flock_p))) { 0 => return,