authorgravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-03-17 21:02:19-06:00
committergravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-03-17 21:02:19-06:00
log613956cc47c2513cdd27d57e5eb2fa36a368c21b
tree17a5808350d53bebf6d24139165c04d92279e864
parent32c58250305540bf33b109f832956777e4bef73c

Remove `fcntlFlock` and replace with plain `fcntl`


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

lib/std/fs.zig+2-2
......@@ -688,7 +688,7 @@ pub const Dir = struct {
688688 flock.l_start = 0;
689689 flock.l_len = 0;
690690 flock.l_pid = 0;
691 try os.fcntlFlock(fd, .SetLockBlocking, &flock);
691 try os.fcntl(fd, os.F_SETLKW, &flock);
692692 locked = true;
693693 }
694694
......@@ -754,7 +754,7 @@ pub const Dir = struct {
754754 flock.l_start = 0;
755755 flock.l_len = 0;
756756 flock.l_pid = 0;
757 try os.fcntlFlock(fd, .SetLockBlocking, &flock);
757 try os.fcntl(fd, os.F_SETLKW, &flock);
758758 }
759759
760760 return File{ .handle = fd, .io_mode = .blocking };
lib/std/os.zig+1-12
......@@ -1140,24 +1140,13 @@ pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*:0]u8)
11401140 allocator.free(envp_buf);
11411141}
11421142
1143pub const LockCmd = enum {
1144 GetLock,
1145 SetLock,
1146 SetLockBlocking,
1147};
1148
11491143pub const FcntlError = error{
11501144 /// The file is locked by another process
11511145 FileLocked,
11521146} || UnexpectedError;
11531147
11541148/// Attempts to get lock the file, blocking if the file is locked.
1155pub fn fcntlFlock(fd: fd_t, lock_cmd: LockCmd, flock_p: *Flock) FcntlError!void {
1156 const cmd: i32 = switch (lock_cmd) {
1157 .GetLock => F_GETLK,
1158 .SetLock => F_SETLK,
1159 .SetLockBlocking => F_SETLKW,
1160 };
1149pub fn fcntl(fd: fd_t, cmd: i32, flock_p: *Flock) FcntlError!void {
11611150 while (true) {
11621151 switch (errno(system.fcntl(fd, cmd, flock_p))) {
11631152 0 => return,