Remove fcntlFlock and replace with plain fcntl

This commit is contained in:
LeRoyce Pearson 2020-03-17 21:02:19 -06:00
parent 32c5825030
commit 613956cc47
2 changed files with 3 additions and 14 deletions

View File

@ -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 };

View File

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