commit 4236ca40cd21895590c580c9a1f56423c2c2f167 (tree)
parent 5fb36d2600b686a5132b42c4824f99dc2412f037
Author: Andrew Kelley <andrew@ziglang.org>
Date: Wed, 23 Jul 2025 23:04:52 -0700
Merge pull request #24561 from linusg/serenity-fixes
Small fixes for SerenityOS
Diffstat:
3 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/lib/std/c.zig b/lib/std/c.zig
@@ -7147,7 +7147,7 @@ pub const dirent = switch (native_os) {
off: off_t,
reclen: c_ushort,
type: u8,
- name: [256:0]u8,
+ name: [255:0]u8,
},
else => void,
};
diff --git a/lib/std/posix.zig b/lib/std/posix.zig
@@ -192,10 +192,27 @@ pub const iovec_const = extern struct {
len: usize,
};
-pub const ACCMODE = enum(u2) {
- RDONLY = 0,
- WRONLY = 1,
- RDWR = 2,
+pub const ACCMODE = switch (native_os) {
+ // POSIX has a note about the access mode values:
+ //
+ // In historical implementations the value of O_RDONLY is zero. Because of
+ // that, it is not possible to detect the presence of O_RDONLY and another
+ // option. Future implementations should encode O_RDONLY and O_WRONLY as
+ // bit flags so that: O_RDONLY | O_WRONLY == O_RDWR
+ //
+ // In practice SerenityOS is the only system supported by Zig that
+ // implements this suggestion.
+ // https://github.com/SerenityOS/serenity/blob/4adc51fdf6af7d50679c48b39362e062f5a3b2cb/Kernel/API/POSIX/fcntl.h#L28-L30
+ .serenity => enum(u2) {
+ RDONLY = 1,
+ WRONLY = 2,
+ RDWR = 3,
+ },
+ else => enum(u2) {
+ RDONLY = 0,
+ WRONLY = 1,
+ RDWR = 2,
+ },
};
pub const TCSA = enum(c_uint) {
diff --git a/src/target.zig b/src/target.zig
@@ -414,6 +414,8 @@ pub fn libcFullLinkFlags(target: *const std.Target) []const []const u8 {
.android, .androideabi, .ohos, .ohoseabi => &.{ "-lm", "-lc", "-ldl" },
else => &.{ "-lm", "-lpthread", "-lc", "-ldl", "-lrt", "-lutil" },
},
+ // On SerenityOS libc includes libm, libpthread, libdl, and libssp.
+ .serenity => &.{"-lc"},
else => &.{},
};
return result;