Merge pull request #6978 from LemonBoy/statshit

Decouple kernel and libc stat definitions
master
Andrew Kelley 2020-11-05 17:27:22 -05:00 committed by GitHub
commit c9551652b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 178 additions and 175 deletions

View File

@ -128,7 +128,7 @@ pub usingnamespace switch (builtin.os.tag) {
},
else => struct {
pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int;
},
};
@ -202,26 +202,26 @@ pub usingnamespace switch (builtin.os.tag) {
pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
},
.windows => struct {
// TODO: copied the else case and removed the socket function (because its in ws2_32)
// need to verify which of these is actually supported on windows
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
pub extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
pub extern "c" fn sched_yield() c_int;
pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
},
else => struct {
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
pub extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
@ -229,7 +229,7 @@ pub usingnamespace switch (builtin.os.tag) {
pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
},
};

View File

@ -30,16 +30,16 @@ pub extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noa
pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;
/// On x86_64 Darwin, fstat has to be manully linked with $INODE64 suffix to force 64bit version.
/// Note that this is fixed on aarch64 and no longer necessary.
extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *libc_stat) c_int;
pub const _fstat = if (builtin.arch == .aarch64) fstat else @"fstat$INODE64";
extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int;
/// On x86_64 Darwin, fstatat has to be manully linked with $INODE64 suffix to force 64bit version.
/// Note that this is fixed on aarch64 and no longer necessary.
extern "c" fn @"fstatat$INODE64"(dirfd: fd_t, path_name: [*:0]const u8, buf: *Stat, flags: u32) c_int;
extern "c" fn @"fstatat$INODE64"(dirfd: fd_t, path_name: [*:0]const u8, buf: *libc_stat, flags: u32) c_int;
pub const _fstatat = if (builtin.arch == .aarch64) fstatat else @"fstatat$INODE64";
pub extern "c" fn mach_absolute_time() u64;

View File

@ -3267,6 +3267,11 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
}
}
pub const Stat = if (builtin.link_libc)
system.libc_stat
else
system.kernel_stat;
pub const FStatError = error{
SystemResources,

View File

@ -72,13 +72,7 @@ pub const Flock = extern struct {
l_whence: i16,
};
/// Renamed to Stat to not conflict with the stat function.
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
/// the structs are inconsistent across operating systems, and
/// in C, macros are used to hide the differences. Here we use
/// methods to accomplish this.
pub const Stat = extern struct {
pub const libc_stat = extern struct {
dev: i32,
mode: u16,
nlink: u16,
@ -102,21 +96,21 @@ pub const Stat = extern struct {
lspare: i32,
qspare: [2]i64,
pub fn atime(self: Stat) timespec {
pub fn atime(self: @This()) timespec {
return timespec{
.tv_sec = self.atimesec,
.tv_nsec = self.atimensec,
};
}
pub fn mtime(self: Stat) timespec {
pub fn mtime(self: @This()) timespec {
return timespec{
.tv_sec = self.mtimesec,
.tv_nsec = self.mtimensec,
};
}
pub fn ctime(self: Stat) timespec {
pub fn ctime(self: @This()) timespec {
return timespec{
.tv_sec = self.ctimesec,
.tv_nsec = self.ctimensec,

View File

@ -152,7 +152,7 @@ pub const PATH_MAX = 1024;
pub const ino_t = c_ulong;
pub const Stat = extern struct {
pub const libc_stat = extern struct {
ino: ino_t,
nlink: c_uint,
dev: c_uint,
@ -172,15 +172,15 @@ pub const Stat = extern struct {
lspare: i32,
qspare1: i64,
qspare2: i64,
pub fn atime(self: Stat) timespec {
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: Stat) timespec {
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: Stat) timespec {
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};

View File

@ -119,13 +119,7 @@ pub const msghdr_const = extern struct {
pub const off_t = i64;
pub const ino_t = u64;
/// Renamed to Stat to not conflict with the stat function.
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
/// the structs are inconsistent across operating systems, and
/// in C, macros are used to hide the differences. Here we use
/// methods to accomplish this.
pub const Stat = extern struct {
pub const libc_stat = extern struct {
dev: u64,
ino: ino_t,
nlink: usize,
@ -149,15 +143,15 @@ pub const Stat = extern struct {
gen: u64,
__spare: [10]u64,
pub fn atime(self: Stat) timespec {
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: Stat) timespec {
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: Stat) timespec {
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};

View File

@ -1152,10 +1152,18 @@ pub const SS_ONSTACK = 1;
pub const SS_DISABLE = 2;
pub const SS_AUTODISARM = 1 << 31;
pub const stack_t = extern struct {
pub const stack_t = if (is_mips)
// IRIX compatible stack_t
extern struct {
ss_sp: [*]u8,
ss_size: usize,
ss_flags: i32,
}
else
extern struct {
ss_sp: [*]u8,
ss_flags: i32,
ss_size: isize,
ss_size: usize,
};
pub const sigval = extern union {
@ -1322,7 +1330,7 @@ pub const io_uring_sqe = extern struct {
buf_index: u16,
personality: u16,
splice_fd_in: i32,
__pad2: [2]u64
__pad2: [2]u64,
};
pub const IOSQE_BIT = extern enum(u8) {

View File

@ -553,13 +553,8 @@ pub const ino_t = u64;
pub const dev_t = u64;
pub const blkcnt_t = i64;
/// Renamed to Stat to not conflict with the stat function.
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
/// the structs are inconsistent across operating systems, and
/// in C, macros are used to hide the differences. Here we use
/// methods to accomplish this.
pub const Stat = extern struct {
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
dev: dev_t,
__dev_padding: u32,
__ino_truncated: u32,
@ -577,19 +572,22 @@ pub const Stat = extern struct {
ctim: timespec,
ino: ino_t,
pub fn atime(self: Stat) timespec {
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: Stat) timespec {
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: Stat) timespec {
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const timespec = extern struct {
tv_sec: i32,
tv_nsec: i32,

View File

@ -424,13 +424,8 @@ pub const ino_t = usize;
pub const dev_t = usize;
pub const blkcnt_t = isize;
/// Renamed to Stat to not conflict with the stat function.
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
/// the structs are inconsistent across operating systems, and
/// in C, macros are used to hide the differences. Here we use
/// methods to accomplish this.
pub const Stat = extern struct {
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
dev: dev_t,
ino: ino_t,
mode: mode_t,
@ -448,19 +443,22 @@ pub const Stat = extern struct {
ctim: timespec,
__unused: [2]u32,
pub fn atime(self: Stat) timespec {
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: Stat) timespec {
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: Stat) timespec {
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const timespec = extern struct {
tv_sec: time_t,
tv_nsec: isize,

View File

@ -546,13 +546,8 @@ pub const ino_t = u64;
pub const dev_t = u64;
pub const blkcnt_t = i64;
/// Renamed to Stat to not conflict with the stat function.
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
/// the structs are inconsistent across operating systems, and
/// in C, macros are used to hide the differences. Here we use
/// methods to accomplish this.
pub const Stat = extern struct {
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
dev: dev_t,
__dev_padding: u32,
__ino_truncated: u32,
@ -570,19 +565,22 @@ pub const Stat = extern struct {
ctim: timespec,
ino: ino_t,
pub fn atime(self: Stat) timespec {
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: Stat) timespec {
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: Stat) timespec {
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const timespec = extern struct {
tv_sec: i32,
tv_nsec: i32,

View File

@ -536,41 +536,74 @@ pub const Flock = extern struct {
pub const blksize_t = i32;
pub const nlink_t = u32;
pub const time_t = isize;
pub const time_t = i32;
pub const mode_t = u32;
pub const off_t = i64;
pub const ino_t = u64;
pub const dev_t = usize;
pub const dev_t = u64;
pub const blkcnt_t = i64;
pub const Stat = extern struct {
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
dev: u32,
__pad0: [3]u32,
__pad0: [3]u32, // Reserved for st_dev expansion
ino: ino_t,
mode: mode_t,
nlink: nlink_t,
uid: uid_t,
gid: gid_t,
rdev: dev_t,
rdev: u32,
__pad1: [3]u32,
size: off_t,
atim: timespec,
mtim: timespec,
ctim: timespec,
blksize: blksize_t,
__pad3: [1]u32,
__pad3: u32,
blocks: blkcnt_t,
__pad4: [14]usize,
pub fn atime(self: Stat) timespec {
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: Stat) timespec {
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: Stat) timespec {
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};
pub const libc_stat = extern struct {
dev: dev_t,
__pad0: [2]u32,
ino: ino_t,
mode: mode_t,
nlink: nlink_t,
uid: uid_t,
gid: gid_t,
rdev: dev_t,
__pad1: [2]u32,
size: off_t,
atim: timespec,
mtim: timespec,
ctim: timespec,
blksize: blksize_t,
__pad3: u32,
blocks: blkcnt_t,
__pad4: [14]u32,
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};

View File

@ -516,13 +516,8 @@ pub const ino_t = u64;
pub const dev_t = u64;
pub const blkcnt_t = i64;
/// Renamed to Stat to not conflict with the stat function.
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
/// the structs are inconsistent across operating systems, and
/// in C, macros are used to hide the differences. Here we use
/// methods to accomplish this.
pub const Stat = extern struct {
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
dev: dev_t,
ino: ino_t,
nlink: nlink_t,
@ -538,19 +533,22 @@ pub const Stat = extern struct {
ctim: timespec,
__unused: [3]u64,
pub fn atime(self: Stat) timespec {
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: Stat) timespec {
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: Stat) timespec {
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const timespec = extern struct {
tv_sec: time_t,
tv_nsec: isize,

View File

@ -381,13 +381,8 @@ pub const Flock = extern struct {
__unused: [4]u8,
};
/// Renamed to Stat to not conflict with the stat function.
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
/// the structs are inconsistent across operating systems, and
/// in C, macros are used to hide the differences. Here we use
/// methods to accomplish this.
pub const Stat = extern struct {
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
dev: dev_t,
ino: ino_t,
mode: mode_t,
@ -405,17 +400,20 @@ pub const Stat = extern struct {
ctim: timespec,
__unused: [2]u32,
pub fn atime(self: Stat) timespec {
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: Stat) timespec {
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: Stat) timespec {
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const Elf_Symndx = u32;

View File

@ -484,11 +484,7 @@ pub const off_t = i64;
pub const ino_t = u64;
pub const mode_t = u32;
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
/// the structs are inconsistent across operating systems, and
/// in C, macros are used to hide the differences. Here we use
/// methods to accomplish this.
// The `stat64` definition used by the libc.
pub const libc_stat = extern struct {
dev: u64,
ino: ino_t,
@ -522,45 +518,40 @@ pub const libc_stat = extern struct {
}
};
// The `stat64` definition used by the kernel.
pub const kernel_stat = extern struct {
dev: u32,
ino: ino_t,
mode: mode_t,
nlink: i16,
dev: u64,
ino: u64,
nlink: u64,
mode: u32,
uid: u32,
gid: u32,
rdev: u32,
__pad0: u32,
size: off_t,
atim: isize,
mtim: isize,
ctim: isize,
rdev: u64,
size: i64,
blksize: i64,
blocks: i64,
blksize: off_t,
blocks: off_t,
atim: timespec,
mtim: timespec,
ctim: timespec,
__unused: [3]u64,
__unused4: [2]isize,
// Hack to make the stdlib not complain about atime
// and friends not being a method.
// TODO what should tv_nsec be filled with?
pub fn atime(self: kernel_stat) timespec {
return timespec{.tv_sec=self.atim, .tv_nsec=0};
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: kernel_stat) timespec {
return timespec{.tv_sec=self.mtim, .tv_nsec=0};
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: kernel_stat) timespec {
return timespec{.tv_sec=self.ctim, .tv_nsec=0};
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};
/// Renamed to Stat to not conflict with the stat function.
pub const Stat = if (std.builtin.link_libc) libc_stat else kernel_stat;
pub const timespec = extern struct {
tv_sec: isize,
tv_nsec: isize,

View File

@ -512,13 +512,8 @@ pub const msghdr_const = extern struct {
pub const off_t = i64;
pub const ino_t = u64;
/// Renamed to Stat to not conflict with the stat function.
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
/// the structs are inconsistent across operating systems, and
/// in C, macros are used to hide the differences. Here we use
/// methods to accomplish this.
pub const Stat = extern struct {
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
dev: u64,
ino: ino_t,
nlink: usize,
@ -537,19 +532,22 @@ pub const Stat = extern struct {
ctim: timespec,
__unused: [3]isize,
pub fn atime(self: Stat) timespec {
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: Stat) timespec {
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: Stat) timespec {
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const timespec = extern struct {
tv_sec: isize,
tv_nsec: isize,

View File

@ -153,13 +153,7 @@ pub const msghdr_const = extern struct {
msg_flags: i32,
};
/// Renamed to Stat to not conflict with the stat function.
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
/// the structs are inconsistent across operating systems, and
/// in C, macros are used to hide the differences. Here we use
/// methods to accomplish this.
pub const Stat = extern struct {
pub const libc_stat = extern struct {
dev: dev_t,
mode: mode_t,
ino: ino_t,
@ -178,15 +172,15 @@ pub const Stat = extern struct {
gen: u32,
__spare: [2]u32,
pub fn atime(self: Stat) timespec {
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: Stat) timespec {
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: Stat) timespec {
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};

View File

@ -152,13 +152,7 @@ pub const msghdr_const = extern struct {
msg_flags: i32,
};
/// Renamed to Stat to not conflict with the stat function.
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
/// the structs are inconsistent across operating systems, and
/// in C, macros are used to hide the differences. Here we use
/// methods to accomplish this.
pub const Stat = extern struct {
pub const libc_stat = extern struct {
mode: mode_t,
dev: dev_t,
ino: ino_t,
@ -176,15 +170,15 @@ pub const Stat = extern struct {
gen: u32,
birthtim: timespec,
pub fn atime(self: Stat) timespec {
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: Stat) timespec {
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: Stat) timespec {
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};

View File

@ -31,7 +31,7 @@ pub const timespec = struct {
}
};
pub const Stat = struct {
pub const kernel_stat = struct {
dev: device_t,
ino: inode_t,
mode: mode_t,

View File

@ -1071,7 +1071,7 @@ pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flag
return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);
}
pub fn fstat(fd: i32, stat_buf: *Stat) usize {
pub fn fstat(fd: i32, stat_buf: *kernel_stat) usize {
if (@hasField(SYS, "fstat64")) {
return syscall2(.fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
} else {
@ -1079,7 +1079,7 @@ pub fn fstat(fd: i32, stat_buf: *Stat) usize {
}
}
pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize {
pub fn stat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {
if (@hasField(SYS, "stat64")) {
return syscall2(.stat64, @ptrToInt(pathname), @ptrToInt(statbuf));
} else {
@ -1087,7 +1087,7 @@ pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize {
}
}
pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {
pub fn lstat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {
if (@hasField(SYS, "lstat64")) {
return syscall2(.lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));
} else {
@ -1095,7 +1095,7 @@ pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {
}
}
pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize {
pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *kernel_stat, flags: u32) usize {
if (@hasField(SYS, "fstatat64")) {
return syscall4(.fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
} else {

View File

@ -2,20 +2,22 @@ usingnamespace @import("../bits.zig");
pub fn syscall_pipe(fd: *[2]i32) usize {
return asm volatile (
\\ mov %%o0, %%o2
\\ mov %[arg], %%g3
\\ t 0x6d
\\ bcc,pt %%xcc, 1f
\\ nop
\\ # Return the error code
\\ ba 2f
\\ neg %%o0
\\1:
\\ st %%o0, [%%o2]
\\ st %%o1, [%%o2 + 4]
\\ st %%o0, [%%g3+0]
\\ st %%o1, [%%g3+4]
\\ clr %%o0
\\2:
: [ret] "={o0}" (-> usize)
: [number] "{$2}" (@enumToInt(SYS.pipe))
: "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
: [number] "{g1}" (@enumToInt(SYS.pipe)),
[arg] "r" (fd)
: "memory", "g3"
);
}
@ -107,7 +109,7 @@ pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
[arg2] "{o1}" (arg2),
[arg3] "{o2}" (arg3),
[arg4] "{o3}" (arg4),
[arg5] "{o4}" (arg5),
[arg5] "{o4}" (arg5)
: "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
);
}
@ -134,7 +136,7 @@ pub fn syscall6(
[arg3] "{o2}" (arg3),
[arg4] "{o3}" (arg4),
[arg5] "{o4}" (arg5),
[arg6] "{o5}" (arg6),
[arg6] "{o5}" (arg6)
: "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
);
}

View File

@ -86,7 +86,7 @@ test "statx" {
else => unreachable,
}
var stat_buf: linux.Stat = undefined;
var stat_buf: linux.kernel_stat = undefined;
switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) {
0 => {},
else => unreachable,