Skip to content

Commit 26bd74e

Browse files
committed
std.posix: Fix ACCMODE values for serenity
1 parent ea90ec4 commit 26bd74e

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/std/posix.zig

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,27 @@ pub const iovec_const = extern struct {
192192
len: usize,
193193
};
194194

195-
pub const ACCMODE = enum(u2) {
196-
RDONLY = 0,
197-
WRONLY = 1,
198-
RDWR = 2,
195+
pub const ACCMODE = switch (native_os) {
196+
// POSIX has a note about the access mode values:
197+
//
198+
// In historical implementations the value of O_RDONLY is zero. Because of
199+
// that, it is not possible to detect the presence of O_RDONLY and another
200+
// option. Future implementations should encode O_RDONLY and O_WRONLY as
201+
// bit flags so that: O_RDONLY | O_WRONLY == O_RDWR
202+
//
203+
// In practice SerenityOS is the only system supported by Zig that
204+
// implements this suggestion.
205+
// https://github.com/SerenityOS/serenity/blob/4adc51fdf6af7d50679c48b39362e062f5a3b2cb/Kernel/API/POSIX/fcntl.h#L28-L30
206+
.serenity => enum(u2) {
207+
RDONLY = 1,
208+
WRONLY = 2,
209+
RDWR = 3,
210+
},
211+
else => enum(u2) {
212+
RDONLY = 0,
213+
WRONLY = 1,
214+
RDWR = 2,
215+
},
199216
};
200217

201218
pub const TCSA = enum(c_uint) {

0 commit comments

Comments
 (0)