| ... | ... | @@ -686,21 +686,25 @@ pub const Dir = struct { |
| 686 | 686 | return self.openFileW(path_w.span(), flags); |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | var os_flags: u32 = os.O_CLOEXEC; |
| 689 | 690 | // Use the O_ locking flags if the os supports them |
| 690 | 691 | // (Or if it's darwin, as darwin's `open` doesn't support the O_SYNC flag) |
| 691 | 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 | | 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) |
| 704 | 708 | @as(u32, os.O_RDWR) |
| 705 | 709 | else if (flags.write) |
| 706 | 710 | @as(u32, os.O_WRONLY) |