authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-08-24 02:27:26+10:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-08-24 02:27:26+10:00
log23a81b439638fee89054ad749f0348ab7d107619
treeef03f241a33f834b9a6fed41302c6c215c2d2a95
parent4e63cae369ec6e333e4aecb3d749bedff6484ee3
signaturelock-open Commit is signed but in an unrecognized format.

std: refactor fs.openFileZ flag handling


1 files changed, 16 insertions(+), 12 deletions(-)

lib/std/fs.zig+16-12
......@@ -686,21 +686,25 @@ pub const Dir = struct {
686686 return self.openFileW(path_w.span(), flags);
687687 }
688688
689 var os_flags: u32 = os.O_CLOEXEC;
689690 // Use the O_ locking flags if the os supports them
690691 // (Or if it's darwin, as darwin's `open` doesn't support the O_SYNC flag)
691692 const has_flock_open_flags = @hasDecl(os, "O_EXLOCK") and !is_darwin;
692 const nonblocking_lock_flag = if (has_flock_open_flags and flags.lock_nonblocking)
693 os.O_NONBLOCK | os.O_SYNC
694 else
695 @as(u32, 0);
696 const lock_flag: u32 = if (has_flock_open_flags) switch (flags.lock) {
697 .None => @as(u32, 0),
698 .Shared => os.O_SHLOCK | nonblocking_lock_flag,
699 .Exclusive => os.O_EXLOCK | nonblocking_lock_flag,
700 } else 0;
701
702 const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;
703 const os_flags = lock_flag | O_LARGEFILE | os.O_CLOEXEC | if (flags.write and flags.read)
693 if (has_flock_open_flags) {
694 const nonblocking_lock_flag = if (flags.lock_nonblocking)
695 os.O_NONBLOCK | os.O_SYNC
696 else
697 @as(u32, 0);
698 os_flags |= switch (flags.lock) {
699 .None => @as(u32, 0),
700 .Shared => os.O_SHLOCK | nonblocking_lock_flag,
701 .Exclusive => os.O_EXLOCK | nonblocking_lock_flag,
702 };
703 }
704 if (@hasDecl(os, "O_LARGEFILE")) {
705 os_flags |= os.O_LARGEFILE;
706 }
707 os_flags |= if (flags.write and flags.read)
704708 @as(u32, os.O_RDWR)
705709 else if (flags.write)
706710 @as(u32, os.O_WRONLY)