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 {...@@ -688,7 +688,7 @@ pub const Dir = struct {
688 flock.l_start = 0;688 flock.l_start = 0;
689 flock.l_len = 0;689 flock.l_len = 0;
690 flock.l_pid = 0;690 flock.l_pid = 0;
691 try os.fcntlFlock(fd, .SetLockBlocking, &flock);691 try os.fcntl(fd, os.F_SETLKW, &flock);
692 locked = true;692 locked = true;
693 }693 }
694694
...@@ -754,7 +754,7 @@ pub const Dir = struct {...@@ -754,7 +754,7 @@ pub const Dir = struct {
754 flock.l_start = 0;754 flock.l_start = 0;
755 flock.l_len = 0;755 flock.l_len = 0;
756 flock.l_pid = 0;756 flock.l_pid = 0;
757 try os.fcntlFlock(fd, .SetLockBlocking, &flock);757 try os.fcntl(fd, os.F_SETLKW, &flock);
758 }758 }
759759
760 return File{ .handle = fd, .io_mode = .blocking };760 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)...@@ -1140,24 +1140,13 @@ pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*:0]u8)
1140 allocator.free(envp_buf);1140 allocator.free(envp_buf);
1141}1141}
11421142
1143pub const LockCmd = enum {
1144 GetLock,
1145 SetLock,
1146 SetLockBlocking,
1147};
1148
1149pub const FcntlError = error{1143pub const FcntlError = error{
1150 /// The file is locked by another process1144 /// The file is locked by another process
1151 FileLocked,1145 FileLocked,
1152} || UnexpectedError;1146} || UnexpectedError;
11531147
1154/// Attempts to get lock the file, blocking if the file is locked.1148/// 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 {1149pub fn fcntl(fd: fd_t, cmd: i32, 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 };
1161 while (true) {1150 while (true) {
1162 switch (errno(system.fcntl(fd, cmd, flock_p))) {1151 switch (errno(system.fcntl(fd, cmd, flock_p))) {
1163 0 => return,1152 0 => return,