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
signature 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 {...@@ -686,21 +686,25 @@ pub const Dir = struct {
686 return self.openFileW(path_w.span(), flags);686 return self.openFileW(path_w.span(), flags);
687 }687 }
688688
689 var os_flags: u32 = os.O_CLOEXEC;
689 // Use the O_ locking flags if the os supports them690 // Use the O_ locking flags if the os supports them
690 // (Or if it's darwin, as darwin's `open` doesn't support the O_SYNC flag)691 // (Or if it's darwin, as darwin's `open` doesn't support the O_SYNC flag)
691 const has_flock_open_flags = @hasDecl(os, "O_EXLOCK") and !is_darwin;692 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 if (has_flock_open_flags) {
693 os.O_NONBLOCK | os.O_SYNC694 const nonblocking_lock_flag = if (flags.lock_nonblocking)
694 else695 os.O_NONBLOCK | os.O_SYNC
695 @as(u32, 0);696 else
696 const lock_flag: u32 = if (has_flock_open_flags) switch (flags.lock) {697 @as(u32, 0);
697 .None => @as(u32, 0),698 os_flags |= switch (flags.lock) {
698 .Shared => os.O_SHLOCK | nonblocking_lock_flag,699 .None => @as(u32, 0),
699 .Exclusive => os.O_EXLOCK | nonblocking_lock_flag,700 .Shared => os.O_SHLOCK | nonblocking_lock_flag,
700 } else 0;701 .Exclusive => os.O_EXLOCK | nonblocking_lock_flag,
701702 };
702 const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;703 }
703 const os_flags = lock_flag | O_LARGEFILE | os.O_CLOEXEC | if (flags.write and flags.read)704 if (@hasDecl(os, "O_LARGEFILE")) {
705 os_flags |= os.O_LARGEFILE;
706 }
707 os_flags |= if (flags.write and flags.read)
704 @as(u32, os.O_RDWR)708 @as(u32, os.O_RDWR)
705 else if (flags.write)709 else if (flags.write)
706 @as(u32, os.O_WRONLY)710 @as(u32, os.O_WRONLY)