Skip to content

Commit 8facfbb

Browse files
committed
std.os.linux: add have_fstat
Change-Id: I65901604839d137bb8bbbe369a49e26777364009
1 parent 21f9f37 commit 8facfbb

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

lib/std/os/linux.zig

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,10 +2201,12 @@ pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flag
22012201
return syscall4(.accept4, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len), flags);
22022202
}
22032203

2204+
// riscv32 and loongarch have made the interesting decision to not implement some of
2205+
// the older stat syscalls, including this one.
2206+
pub const have_fstat = !(native_arch == .riscv32 or is_loongarch);
2207+
22042208
pub fn fstat(fd: i32, stat_buf: *Stat) usize {
2205-
if (native_arch == .riscv32 or native_arch.isLoongArch()) {
2206-
// riscv32 and loongarch have made the interesting decision to not implement some of
2207-
// the older stat syscalls, including this one.
2209+
if (!have_fstat) {
22082210
@compileError("No fstat syscall on this architecture.");
22092211
} else if (@hasField(SYS, "fstat64")) {
22102212
return syscall2(.fstat64, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(stat_buf));
@@ -2214,9 +2216,7 @@ pub fn fstat(fd: i32, stat_buf: *Stat) usize {
22142216
}
22152217

22162218
pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize {
2217-
if (native_arch == .riscv32 or native_arch.isLoongArch()) {
2218-
// riscv32 and loongarch have made the interesting decision to not implement some of
2219-
// the older stat syscalls, including this one.
2219+
if (!have_fstat) {
22202220
@compileError("No stat syscall on this architecture.");
22212221
} else if (@hasField(SYS, "stat64")) {
22222222
return syscall2(.stat64, @intFromPtr(pathname), @intFromPtr(statbuf));
@@ -2226,9 +2226,7 @@ pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize {
22262226
}
22272227

22282228
pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {
2229-
if (native_arch == .riscv32 or native_arch.isLoongArch()) {
2230-
// riscv32 and loongarch have made the interesting decision to not implement some of
2231-
// the older stat syscalls, including this one.
2229+
if (!have_fstat) {
22322230
@compileError("No lstat syscall on this architecture.");
22332231
} else if (@hasField(SYS, "lstat64")) {
22342232
return syscall2(.lstat64, @intFromPtr(pathname), @intFromPtr(statbuf));
@@ -2238,9 +2236,7 @@ pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {
22382236
}
22392237

22402238
pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize {
2241-
if (native_arch == .riscv32 or native_arch.isLoongArch()) {
2242-
// riscv32 and loongarch have made the interesting decision to not implement some of
2243-
// the older stat syscalls, including this one.
2239+
if (!have_fstat) {
22442240
@compileError("No fstatat syscall on this architecture.");
22452241
} else if (@hasField(SYS, "fstatat64")) {
22462242
return syscall4(.fstatat64, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), @intFromPtr(stat_buf), flags);

0 commit comments

Comments
 (0)