zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 613956cc47c2513cdd27d57e5eb2fa36a368c21b (tree)
parent 32c58250305540bf33b109f832956777e4bef73c
Author: LeRoyce Pearson <leroycepearson@geemili.xyz>
Date:   Tue, 17 Mar 2020 21:02:19 -0600

Remove `fcntlFlock` and replace with plain `fcntl`

Diffstat:
Mlib/std/fs.zig | 4++--
Mlib/std/os.zig | 13+------------
2 files changed, 3 insertions(+), 14 deletions(-)

diff --git 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 @@ -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,