authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-05 17:27:22-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-11-05 17:27:22-05:00
logc9551652b01bf47a94c139846f22c5df85d07283
tree9f7c957dedad2c8e7e72c28ae065a58619c417ba
parentcf7505da1f60757d9fabda20560191bba72ebdbe
parentcca6b1113825e5d9723568a398d270ceac6da92c
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6978 from LemonBoy/statshit

Decouple kernel and libc stat definitions

21 files changed, 178 insertions(+), 175 deletions(-)

lib/std/c.zig+6-6
......@@ -128,7 +128,7 @@ pub usingnamespace switch (builtin.os.tag) {
128128 },
129129 else => struct {
130130 pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
131 pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
131 pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int;
132132 },
133133};
134134
......@@ -202,26 +202,26 @@ pub usingnamespace switch (builtin.os.tag) {
202202 pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
203203 pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
204204 pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
205 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
205 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
206206 },
207207 .windows => struct {
208208 // TODO: copied the else case and removed the socket function (because its in ws2_32)
209209 // need to verify which of these is actually supported on windows
210210 pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
211211 pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
212 pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
212 pub extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;
213213 pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
214214 pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
215215 pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
216216 pub extern "c" fn sched_yield() c_int;
217217 pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
218218 pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
219 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
219 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
220220 },
221221 else => struct {
222222 pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
223223 pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
224 pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
224 pub extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;
225225 pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
226226 pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
227227 pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
......@@ -229,7 +229,7 @@ pub usingnamespace switch (builtin.os.tag) {
229229 pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
230230 pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
231231 pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
232 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
232 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
233233 },
234234};
235235
lib/std/c/darwin.zig+4-4
......@@ -30,16 +30,16 @@ pub extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noa
3030
3131pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
3232
33extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
33extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;
3434/// On x86_64 Darwin, fstat has to be manully linked with $INODE64 suffix to force 64bit version.
3535/// Note that this is fixed on aarch64 and no longer necessary.
36extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
36extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *libc_stat) c_int;
3737pub const _fstat = if (builtin.arch == .aarch64) fstat else @"fstat$INODE64";
3838
39extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
39extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int;
4040/// On x86_64 Darwin, fstatat has to be manully linked with $INODE64 suffix to force 64bit version.
4141/// Note that this is fixed on aarch64 and no longer necessary.
42extern "c" fn @"fstatat$INODE64"(dirfd: fd_t, path_name: [*:0]const u8, buf: *Stat, flags: u32) c_int;
42extern "c" fn @"fstatat$INODE64"(dirfd: fd_t, path_name: [*:0]const u8, buf: *libc_stat, flags: u32) c_int;
4343pub const _fstatat = if (builtin.arch == .aarch64) fstatat else @"fstatat$INODE64";
4444
4545pub extern "c" fn mach_absolute_time() u64;
lib/std/os.zig+5
......@@ -3267,6 +3267,11 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
32673267 }
32683268}
32693269
3270pub const Stat = if (builtin.link_libc)
3271 system.libc_stat
3272else
3273 system.kernel_stat;
3274
32703275pub const FStatError = error{
32713276 SystemResources,
32723277
lib/std/os/bits/darwin.zig+4-10
......@@ -72,13 +72,7 @@ pub const Flock = extern struct {
7272 l_whence: i16,
7373};
7474
75/// Renamed to Stat to not conflict with the stat function.
76/// atime, mtime, and ctime have functions to return `timespec`,
77/// because although this is a POSIX API, the layout and names of
78/// the structs are inconsistent across operating systems, and
79/// in C, macros are used to hide the differences. Here we use
80/// methods to accomplish this.
81pub const Stat = extern struct {
75pub const libc_stat = extern struct {
8276 dev: i32,
8377 mode: u16,
8478 nlink: u16,
......@@ -102,21 +96,21 @@ pub const Stat = extern struct {
10296 lspare: i32,
10397 qspare: [2]i64,
10498
105 pub fn atime(self: Stat) timespec {
99 pub fn atime(self: @This()) timespec {
106100 return timespec{
107101 .tv_sec = self.atimesec,
108102 .tv_nsec = self.atimensec,
109103 };
110104 }
111105
112 pub fn mtime(self: Stat) timespec {
106 pub fn mtime(self: @This()) timespec {
113107 return timespec{
114108 .tv_sec = self.mtimesec,
115109 .tv_nsec = self.mtimensec,
116110 };
117111 }
118112
119 pub fn ctime(self: Stat) timespec {
113 pub fn ctime(self: @This()) timespec {
120114 return timespec{
121115 .tv_sec = self.ctimesec,
122116 .tv_nsec = self.ctimensec,
lib/std/os/bits/dragonfly.zig+4-4
......@@ -152,7 +152,7 @@ pub const PATH_MAX = 1024;
152152
153153pub const ino_t = c_ulong;
154154
155pub const Stat = extern struct {
155pub const libc_stat = extern struct {
156156 ino: ino_t,
157157 nlink: c_uint,
158158 dev: c_uint,
......@@ -172,15 +172,15 @@ pub const Stat = extern struct {
172172 lspare: i32,
173173 qspare1: i64,
174174 qspare2: i64,
175 pub fn atime(self: Stat) timespec {
175 pub fn atime(self: @This()) timespec {
176176 return self.atim;
177177 }
178178
179 pub fn mtime(self: Stat) timespec {
179 pub fn mtime(self: @This()) timespec {
180180 return self.mtim;
181181 }
182182
183 pub fn ctime(self: Stat) timespec {
183 pub fn ctime(self: @This()) timespec {
184184 return self.ctim;
185185 }
186186};
lib/std/os/bits/freebsd.zig+4-10
......@@ -119,13 +119,7 @@ pub const msghdr_const = extern struct {
119119pub const off_t = i64;
120120pub const ino_t = u64;
121121
122/// Renamed to Stat to not conflict with the stat function.
123/// atime, mtime, and ctime have functions to return `timespec`,
124/// because although this is a POSIX API, the layout and names of
125/// the structs are inconsistent across operating systems, and
126/// in C, macros are used to hide the differences. Here we use
127/// methods to accomplish this.
128pub const Stat = extern struct {
122pub const libc_stat = extern struct {
129123 dev: u64,
130124 ino: ino_t,
131125 nlink: usize,
......@@ -149,15 +143,15 @@ pub const Stat = extern struct {
149143 gen: u64,
150144 __spare: [10]u64,
151145
152 pub fn atime(self: Stat) timespec {
146 pub fn atime(self: @This()) timespec {
153147 return self.atim;
154148 }
155149
156 pub fn mtime(self: Stat) timespec {
150 pub fn mtime(self: @This()) timespec {
157151 return self.mtim;
158152 }
159153
160 pub fn ctime(self: Stat) timespec {
154 pub fn ctime(self: @This()) timespec {
161155 return self.ctim;
162156 }
163157};
lib/std/os/bits/linux.zig+15-7
......@@ -1152,11 +1152,19 @@ pub const SS_ONSTACK = 1;
11521152pub const SS_DISABLE = 2;
11531153pub const SS_AUTODISARM = 1 << 31;
11541154
1155pub const stack_t = extern struct {
1156 ss_sp: [*]u8,
1157 ss_flags: i32,
1158 ss_size: isize,
1159};
1155pub const stack_t = if (is_mips)
1156 // IRIX compatible stack_t
1157 extern struct {
1158 ss_sp: [*]u8,
1159 ss_size: usize,
1160 ss_flags: i32,
1161 }
1162else
1163 extern struct {
1164 ss_sp: [*]u8,
1165 ss_flags: i32,
1166 ss_size: usize,
1167 };
11601168
11611169pub const sigval = extern union {
11621170 int: i32,
......@@ -1322,7 +1330,7 @@ pub const io_uring_sqe = extern struct {
13221330 buf_index: u16,
13231331 personality: u16,
13241332 splice_fd_in: i32,
1325 __pad2: [2]u64
1333 __pad2: [2]u64,
13261334};
13271335
13281336pub const IOSQE_BIT = extern enum(u8) {
......@@ -1332,7 +1340,7 @@ pub const IOSQE_BIT = extern enum(u8) {
13321340 IO_HARDLINK,
13331341 ASYNC,
13341342 BUFFER_SELECT,
1335
1343
13361344 _,
13371345};
13381346
lib/std/os/bits/linux/arm-eabi.zig+8-10
......@@ -553,13 +553,8 @@ pub const ino_t = u64;
553553pub const dev_t = u64;
554554pub const blkcnt_t = i64;
555555
556/// Renamed to Stat to not conflict with the stat function.
557/// atime, mtime, and ctime have functions to return `timespec`,
558/// because although this is a POSIX API, the layout and names of
559/// the structs are inconsistent across operating systems, and
560/// in C, macros are used to hide the differences. Here we use
561/// methods to accomplish this.
562pub const Stat = extern struct {
556// The `stat` definition used by the Linux kernel.
557pub const kernel_stat = extern struct {
563558 dev: dev_t,
564559 __dev_padding: u32,
565560 __ino_truncated: u32,
......@@ -577,19 +572,22 @@ pub const Stat = extern struct {
577572 ctim: timespec,
578573 ino: ino_t,
579574
580 pub fn atime(self: Stat) timespec {
575 pub fn atime(self: @This()) timespec {
581576 return self.atim;
582577 }
583578
584 pub fn mtime(self: Stat) timespec {
579 pub fn mtime(self: @This()) timespec {
585580 return self.mtim;
586581 }
587582
588 pub fn ctime(self: Stat) timespec {
583 pub fn ctime(self: @This()) timespec {
589584 return self.ctim;
590585 }
591586};
592587
588// The `stat64` definition used by the libc.
589pub const libc_stat = kernel_stat;
590
593591pub const timespec = extern struct {
594592 tv_sec: i32,
595593 tv_nsec: i32,
lib/std/os/bits/linux/arm64.zig+8-10
......@@ -424,13 +424,8 @@ pub const ino_t = usize;
424424pub const dev_t = usize;
425425pub const blkcnt_t = isize;
426426
427/// Renamed to Stat to not conflict with the stat function.
428/// atime, mtime, and ctime have functions to return `timespec`,
429/// because although this is a POSIX API, the layout and names of
430/// the structs are inconsistent across operating systems, and
431/// in C, macros are used to hide the differences. Here we use
432/// methods to accomplish this.
433pub const Stat = extern struct {
427// The `stat` definition used by the Linux kernel.
428pub const kernel_stat = extern struct {
434429 dev: dev_t,
435430 ino: ino_t,
436431 mode: mode_t,
......@@ -448,19 +443,22 @@ pub const Stat = extern struct {
448443 ctim: timespec,
449444 __unused: [2]u32,
450445
451 pub fn atime(self: Stat) timespec {
446 pub fn atime(self: @This()) timespec {
452447 return self.atim;
453448 }
454449
455 pub fn mtime(self: Stat) timespec {
450 pub fn mtime(self: @This()) timespec {
456451 return self.mtim;
457452 }
458453
459 pub fn ctime(self: Stat) timespec {
454 pub fn ctime(self: @This()) timespec {
460455 return self.ctim;
461456 }
462457};
463458
459// The `stat64` definition used by the libc.
460pub const libc_stat = kernel_stat;
461
464462pub const timespec = extern struct {
465463 tv_sec: time_t,
466464 tv_nsec: isize,
lib/std/os/bits/linux/i386.zig+8-10
......@@ -546,13 +546,8 @@ pub const ino_t = u64;
546546pub const dev_t = u64;
547547pub const blkcnt_t = i64;
548548
549/// Renamed to Stat to not conflict with the stat function.
550/// atime, mtime, and ctime have functions to return `timespec`,
551/// because although this is a POSIX API, the layout and names of
552/// the structs are inconsistent across operating systems, and
553/// in C, macros are used to hide the differences. Here we use
554/// methods to accomplish this.
555pub const Stat = extern struct {
549// The `stat` definition used by the Linux kernel.
550pub const kernel_stat = extern struct {
556551 dev: dev_t,
557552 __dev_padding: u32,
558553 __ino_truncated: u32,
......@@ -570,19 +565,22 @@ pub const Stat = extern struct {
570565 ctim: timespec,
571566 ino: ino_t,
572567
573 pub fn atime(self: Stat) timespec {
568 pub fn atime(self: @This()) timespec {
574569 return self.atim;
575570 }
576571
577 pub fn mtime(self: Stat) timespec {
572 pub fn mtime(self: @This()) timespec {
578573 return self.mtim;
579574 }
580575
581 pub fn ctime(self: Stat) timespec {
576 pub fn ctime(self: @This()) timespec {
582577 return self.ctim;
583578 }
584579};
585580
581// The `stat64` definition used by the libc.
582pub const libc_stat = kernel_stat;
583
586584pub const timespec = extern struct {
587585 tv_sec: i32,
588586 tv_nsec: i32,
lib/std/os/bits/linux/mips.zig+42-9
......@@ -536,41 +536,74 @@ pub const Flock = extern struct {
536536
537537pub const blksize_t = i32;
538538pub const nlink_t = u32;
539pub const time_t = isize;
539pub const time_t = i32;
540540pub const mode_t = u32;
541541pub const off_t = i64;
542542pub const ino_t = u64;
543pub const dev_t = usize;
543pub const dev_t = u64;
544544pub const blkcnt_t = i64;
545545
546pub const Stat = extern struct {
546// The `stat` definition used by the Linux kernel.
547pub const kernel_stat = extern struct {
547548 dev: u32,
548 __pad0: [3]u32,
549 __pad0: [3]u32, // Reserved for st_dev expansion
549550 ino: ino_t,
550551 mode: mode_t,
551552 nlink: nlink_t,
552553 uid: uid_t,
553554 gid: gid_t,
554 rdev: dev_t,
555 rdev: u32,
555556 __pad1: [3]u32,
556557 size: off_t,
557558 atim: timespec,
558559 mtim: timespec,
559560 ctim: timespec,
560561 blksize: blksize_t,
561 __pad3: [1]u32,
562 __pad3: u32,
562563 blocks: blkcnt_t,
563564 __pad4: [14]usize,
564565
565 pub fn atime(self: Stat) timespec {
566 pub fn atime(self: @This()) timespec {
567 return self.atim;
568 }
569
570 pub fn mtime(self: @This()) timespec {
571 return self.mtim;
572 }
573
574 pub fn ctime(self: @This()) timespec {
575 return self.ctim;
576 }
577};
578
579pub const libc_stat = extern struct {
580 dev: dev_t,
581 __pad0: [2]u32,
582 ino: ino_t,
583 mode: mode_t,
584 nlink: nlink_t,
585 uid: uid_t,
586 gid: gid_t,
587 rdev: dev_t,
588 __pad1: [2]u32,
589 size: off_t,
590 atim: timespec,
591 mtim: timespec,
592 ctim: timespec,
593 blksize: blksize_t,
594 __pad3: u32,
595 blocks: blkcnt_t,
596 __pad4: [14]u32,
597
598 pub fn atime(self: @This()) timespec {
566599 return self.atim;
567600 }
568601
569 pub fn mtime(self: Stat) timespec {
602 pub fn mtime(self: @This()) timespec {
570603 return self.mtim;
571604 }
572605
573 pub fn ctime(self: Stat) timespec {
606 pub fn ctime(self: @This()) timespec {
574607 return self.ctim;
575608 }
576609};
lib/std/os/bits/linux/powerpc64.zig+8-10
......@@ -516,13 +516,8 @@ pub const ino_t = u64;
516516pub const dev_t = u64;
517517pub const blkcnt_t = i64;
518518
519/// Renamed to Stat to not conflict with the stat function.
520/// atime, mtime, and ctime have functions to return `timespec`,
521/// because although this is a POSIX API, the layout and names of
522/// the structs are inconsistent across operating systems, and
523/// in C, macros are used to hide the differences. Here we use
524/// methods to accomplish this.
525pub const Stat = extern struct {
519// The `stat` definition used by the Linux kernel.
520pub const kernel_stat = extern struct {
526521 dev: dev_t,
527522 ino: ino_t,
528523 nlink: nlink_t,
......@@ -538,19 +533,22 @@ pub const Stat = extern struct {
538533 ctim: timespec,
539534 __unused: [3]u64,
540535
541 pub fn atime(self: Stat) timespec {
536 pub fn atime(self: @This()) timespec {
542537 return self.atim;
543538 }
544539
545 pub fn mtime(self: Stat) timespec {
540 pub fn mtime(self: @This()) timespec {
546541 return self.mtim;
547542 }
548543
549 pub fn ctime(self: Stat) timespec {
544 pub fn ctime(self: @This()) timespec {
550545 return self.ctim;
551546 }
552547};
553548
549// The `stat64` definition used by the libc.
550pub const libc_stat = kernel_stat;
551
554552pub const timespec = extern struct {
555553 tv_sec: time_t,
556554 tv_nsec: isize,
lib/std/os/bits/linux/riscv64.zig+8-10
......@@ -381,13 +381,8 @@ pub const Flock = extern struct {
381381 __unused: [4]u8,
382382};
383383
384/// Renamed to Stat to not conflict with the stat function.
385/// atime, mtime, and ctime have functions to return `timespec`,
386/// because although this is a POSIX API, the layout and names of
387/// the structs are inconsistent across operating systems, and
388/// in C, macros are used to hide the differences. Here we use
389/// methods to accomplish this.
390pub const Stat = extern struct {
384// The `stat` definition used by the Linux kernel.
385pub const kernel_stat = extern struct {
391386 dev: dev_t,
392387 ino: ino_t,
393388 mode: mode_t,
......@@ -405,17 +400,20 @@ pub const Stat = extern struct {
405400 ctim: timespec,
406401 __unused: [2]u32,
407402
408 pub fn atime(self: Stat) timespec {
403 pub fn atime(self: @This()) timespec {
409404 return self.atim;
410405 }
411406
412 pub fn mtime(self: Stat) timespec {
407 pub fn mtime(self: @This()) timespec {
413408 return self.mtim;
414409 }
415410
416 pub fn ctime(self: Stat) timespec {
411 pub fn ctime(self: @This()) timespec {
417412 return self.ctim;
418413 }
419414};
420415
416// The `stat64` definition used by the libc.
417pub const libc_stat = kernel_stat;
418
421419pub const Elf_Symndx = u32;
lib/std/os/bits/linux/sparc64.zig+21-30
......@@ -484,11 +484,7 @@ pub const off_t = i64;
484484pub const ino_t = u64;
485485pub const mode_t = u32;
486486
487/// atime, mtime, and ctime have functions to return `timespec`,
488/// because although this is a POSIX API, the layout and names of
489/// the structs are inconsistent across operating systems, and
490/// in C, macros are used to hide the differences. Here we use
491/// methods to accomplish this.
487// The `stat64` definition used by the libc.
492488pub const libc_stat = extern struct {
493489 dev: u64,
494490 ino: ino_t,
......@@ -522,45 +518,40 @@ pub const libc_stat = extern struct {
522518 }
523519};
524520
521// The `stat64` definition used by the kernel.
525522pub const kernel_stat = extern struct {
526 dev: u32,
527 ino: ino_t,
528 mode: mode_t,
529 nlink: i16,
523 dev: u64,
524 ino: u64,
525 nlink: u64,
530526
527 mode: u32,
531528 uid: u32,
532529 gid: u32,
533 rdev: u32,
534
535 size: off_t,
536 atim: isize,
537 mtim: isize,
538 ctim: isize,
530 __pad0: u32,
539531
540 blksize: off_t,
541 blocks: off_t,
532 rdev: u64,
533 size: i64,
534 blksize: i64,
535 blocks: i64,
542536
543 __unused4: [2]isize,
537 atim: timespec,
538 mtim: timespec,
539 ctim: timespec,
540 __unused: [3]u64,
544541
545 // Hack to make the stdlib not complain about atime
546 // and friends not being a method.
547 // TODO what should tv_nsec be filled with?
548 pub fn atime(self: kernel_stat) timespec {
549 return timespec{.tv_sec=self.atim, .tv_nsec=0};
542 pub fn atime(self: @This()) timespec {
543 return self.atim;
550544 }
551545
552 pub fn mtime(self: kernel_stat) timespec {
553 return timespec{.tv_sec=self.mtim, .tv_nsec=0};
546 pub fn mtime(self: @This()) timespec {
547 return self.mtim;
554548 }
555549
556 pub fn ctime(self: kernel_stat) timespec {
557 return timespec{.tv_sec=self.ctim, .tv_nsec=0};
550 pub fn ctime(self: @This()) timespec {
551 return self.ctim;
558552 }
559553};
560554
561/// Renamed to Stat to not conflict with the stat function.
562pub const Stat = if (std.builtin.link_libc) libc_stat else kernel_stat;
563
564555pub const timespec = extern struct {
565556 tv_sec: isize,
566557 tv_nsec: isize,
lib/std/os/bits/linux/x86_64.zig+8-10
......@@ -512,13 +512,8 @@ pub const msghdr_const = extern struct {
512512pub const off_t = i64;
513513pub const ino_t = u64;
514514
515/// Renamed to Stat to not conflict with the stat function.
516/// atime, mtime, and ctime have functions to return `timespec`,
517/// because although this is a POSIX API, the layout and names of
518/// the structs are inconsistent across operating systems, and
519/// in C, macros are used to hide the differences. Here we use
520/// methods to accomplish this.
521pub const Stat = extern struct {
515// The `stat` definition used by the Linux kernel.
516pub const kernel_stat = extern struct {
522517 dev: u64,
523518 ino: ino_t,
524519 nlink: usize,
......@@ -537,19 +532,22 @@ pub const Stat = extern struct {
537532 ctim: timespec,
538533 __unused: [3]isize,
539534
540 pub fn atime(self: Stat) timespec {
535 pub fn atime(self: @This()) timespec {
541536 return self.atim;
542537 }
543538
544 pub fn mtime(self: Stat) timespec {
539 pub fn mtime(self: @This()) timespec {
545540 return self.mtim;
546541 }
547542
548 pub fn ctime(self: Stat) timespec {
543 pub fn ctime(self: @This()) timespec {
549544 return self.ctim;
550545 }
551546};
552547
548// The `stat64` definition used by the libc.
549pub const libc_stat = kernel_stat;
550
553551pub const timespec = extern struct {
554552 tv_sec: isize,
555553 tv_nsec: isize,
lib/std/os/bits/netbsd.zig+4-10
......@@ -153,13 +153,7 @@ pub const msghdr_const = extern struct {
153153 msg_flags: i32,
154154};
155155
156/// Renamed to Stat to not conflict with the stat function.
157/// atime, mtime, and ctime have functions to return `timespec`,
158/// because although this is a POSIX API, the layout and names of
159/// the structs are inconsistent across operating systems, and
160/// in C, macros are used to hide the differences. Here we use
161/// methods to accomplish this.
162pub const Stat = extern struct {
156pub const libc_stat = extern struct {
163157 dev: dev_t,
164158 mode: mode_t,
165159 ino: ino_t,
......@@ -178,15 +172,15 @@ pub const Stat = extern struct {
178172 gen: u32,
179173 __spare: [2]u32,
180174
181 pub fn atime(self: Stat) timespec {
175 pub fn atime(self: @This()) timespec {
182176 return self.atim;
183177 }
184178
185 pub fn mtime(self: Stat) timespec {
179 pub fn mtime(self: @This()) timespec {
186180 return self.mtim;
187181 }
188182
189 pub fn ctime(self: Stat) timespec {
183 pub fn ctime(self: @This()) timespec {
190184 return self.ctim;
191185 }
192186};
lib/std/os/bits/openbsd.zig+4-10
......@@ -152,13 +152,7 @@ pub const msghdr_const = extern struct {
152152 msg_flags: i32,
153153};
154154
155/// Renamed to Stat to not conflict with the stat function.
156/// atime, mtime, and ctime have functions to return `timespec`,
157/// because although this is a POSIX API, the layout and names of
158/// the structs are inconsistent across operating systems, and
159/// in C, macros are used to hide the differences. Here we use
160/// methods to accomplish this.
161pub const Stat = extern struct {
155pub const libc_stat = extern struct {
162156 mode: mode_t,
163157 dev: dev_t,
164158 ino: ino_t,
......@@ -176,15 +170,15 @@ pub const Stat = extern struct {
176170 gen: u32,
177171 birthtim: timespec,
178172
179 pub fn atime(self: Stat) timespec {
173 pub fn atime(self: @This()) timespec {
180174 return self.atim;
181175 }
182176
183 pub fn mtime(self: Stat) timespec {
177 pub fn mtime(self: @This()) timespec {
184178 return self.mtim;
185179 }
186180
187 pub fn ctime(self: Stat) timespec {
181 pub fn ctime(self: @This()) timespec {
188182 return self.ctim;
189183 }
190184};
lib/std/os/bits/wasi.zig+1-1
......@@ -31,7 +31,7 @@ pub const timespec = struct {
3131 }
3232};
3333
34pub const Stat = struct {
34pub const kernel_stat = struct {
3535 dev: device_t,
3636 ino: inode_t,
3737 mode: mode_t,
lib/std/os/linux.zig+4-4
......@@ -1071,7 +1071,7 @@ pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flag
10711071 return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);
10721072}
10731073
1074pub fn fstat(fd: i32, stat_buf: *Stat) usize {
1074pub fn fstat(fd: i32, stat_buf: *kernel_stat) usize {
10751075 if (@hasField(SYS, "fstat64")) {
10761076 return syscall2(.fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
10771077 } else {
......@@ -1079,7 +1079,7 @@ pub fn fstat(fd: i32, stat_buf: *Stat) usize {
10791079 }
10801080}
10811081
1082pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize {
1082pub fn stat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {
10831083 if (@hasField(SYS, "stat64")) {
10841084 return syscall2(.stat64, @ptrToInt(pathname), @ptrToInt(statbuf));
10851085 } else {
......@@ -1087,7 +1087,7 @@ pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize {
10871087 }
10881088}
10891089
1090pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {
1090pub fn lstat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {
10911091 if (@hasField(SYS, "lstat64")) {
10921092 return syscall2(.lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));
10931093 } else {
......@@ -1095,7 +1095,7 @@ pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {
10951095 }
10961096}
10971097
1098pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize {
1098pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *kernel_stat, flags: u32) usize {
10991099 if (@hasField(SYS, "fstatat64")) {
11001100 return syscall4(.fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
11011101 } else {
lib/std/os/linux/sparc64.zig+11-9
......@@ -2,20 +2,22 @@ usingnamespace @import("../bits.zig");
22
33pub fn syscall_pipe(fd: *[2]i32) usize {
44 return asm volatile (
5 \\ mov %%o0, %%o2
5 \\ mov %[arg], %%g3
66 \\ t 0x6d
77 \\ bcc,pt %%xcc, 1f
88 \\ nop
9 \\ # Return the error code
910 \\ ba 2f
1011 \\ neg %%o0
11 \\ 1:
12 \\ st %%o0, [%%o2]
13 \\ st %%o1, [%%o2 + 4]
12 \\1:
13 \\ st %%o0, [%%g3+0]
14 \\ st %%o1, [%%g3+4]
1415 \\ clr %%o0
15 \\ 2:
16 \\2:
1617 : [ret] "={o0}" (-> usize)
17 : [number] "{$2}" (@enumToInt(SYS.pipe))
18 : "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
18 : [number] "{g1}" (@enumToInt(SYS.pipe)),
19 [arg] "r" (fd)
20 : "memory", "g3"
1921 );
2022}
2123
......@@ -107,7 +109,7 @@ pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
107109 [arg2] "{o1}" (arg2),
108110 [arg3] "{o2}" (arg3),
109111 [arg4] "{o3}" (arg4),
110 [arg5] "{o4}" (arg5),
112 [arg5] "{o4}" (arg5)
111113 : "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
112114 );
113115}
......@@ -134,7 +136,7 @@ pub fn syscall6(
134136 [arg3] "{o2}" (arg3),
135137 [arg4] "{o3}" (arg4),
136138 [arg5] "{o4}" (arg5),
137 [arg6] "{o5}" (arg6),
139 [arg6] "{o5}" (arg6)
138140 : "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
139141 );
140142}
lib/std/os/linux/test.zig+1-1
......@@ -86,7 +86,7 @@ test "statx" {
8686 else => unreachable,
8787 }
8888
89 var stat_buf: linux.Stat = undefined;
89 var stat_buf: linux.kernel_stat = undefined;
9090 switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) {
9191 0 => {},
9292 else => unreachable,