| author | |
| committer | |
| log | 613956cc47c2513cdd27d57e5eb2fa36a368c21b |
| tree | 17a5808350d53bebf6d24139165c04d92279e864 |
| parent | 32c58250305540bf33b109f832956777e4bef73c |
2 files changed, 3 insertions(+), 14 deletions(-)
lib/std/fs.zig+2-2| ... | ... | @@ -688,7 +688,7 @@ pub const Dir = struct { |
| 688 | 688 | flock.l_start = 0; |
| 689 | 689 | flock.l_len = 0; |
| 690 | 690 | flock.l_pid = 0; |
| 691 | try os.fcntlFlock(fd, .SetLockBlocking, &flock); | |
| 691 | try os.fcntl(fd, os.F_SETLKW, &flock); | |
| 692 | 692 | locked = true; |
| 693 | 693 | } |
| 694 | 694 | |
| ... | ... | @@ -754,7 +754,7 @@ pub const Dir = struct { |
| 754 | 754 | flock.l_start = 0; |
| 755 | 755 | flock.l_len = 0; |
| 756 | 756 | flock.l_pid = 0; |
| 757 | try os.fcntlFlock(fd, .SetLockBlocking, &flock); | |
| 757 | try os.fcntl(fd, os.F_SETLKW, &flock); | |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 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 | 1140 | allocator.free(envp_buf); |
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | pub const LockCmd = enum { | |
| 1144 | GetLock, | |
| 1145 | SetLock, | |
| 1146 | SetLockBlocking, | |
| 1147 | }; | |
| 1148 | ||
| 1149 | 1143 | pub const FcntlError = error{ |
| 1150 | 1144 | /// The file is locked by another process |
| 1151 | 1145 | FileLocked, |
| 1152 | 1146 | } || UnexpectedError; |
| 1153 | 1147 | |
| 1154 | 1148 | /// Attempts to get lock the file, blocking if the file is locked. |
| 1155 | pub 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 | }; | |
| 1149 | pub fn fcntl(fd: fd_t, cmd: i32, flock_p: *Flock) FcntlError!void { | |
| 1161 | 1150 | while (true) { |
| 1162 | 1151 | switch (errno(system.fcntl(fd, cmd, flock_p))) { |
| 1163 | 1152 | 0 => return, |