mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
Remove fcntlFlock and replace with plain fcntl
This commit is contained in:
parent
32c5825030
commit
613956cc47
@ -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 };
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user