authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2020-10-25 23:52:08+07:00
committergravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2020-10-25 23:52:08+07:00
logcbc8750502630cc38c0c776a76393e766c609124
tree5dfd8a254742cb4c90f1cb96f71edbc5ca44f308
parent3ce9428e3d617625227bf6b61cae0b4ded946bfe

Separate libc stat and kernel stat definitions


1 files changed, 41 insertions(+), 4 deletions(-)

lib/std/os/bits/linux/sparc64.zig+41-4
...@@ -12,8 +12,6 @@ const socklen_t = linux.socklen_t;...@@ -12,8 +12,6 @@ const socklen_t = linux.socklen_t;
12const iovec = linux.iovec;12const iovec = linux.iovec;
13const iovec_const = linux.iovec_const;13const iovec_const = linux.iovec_const;
1414
15pub const mode_t = usize;
16
17pub const SYS = extern enum(usize) {15pub const SYS = extern enum(usize) {
18 restart_syscall = 0,16 restart_syscall = 0,
19 exit = 1,17 exit = 1,
...@@ -484,14 +482,14 @@ pub const msghdr_const = extern struct {...@@ -484,14 +482,14 @@ pub const msghdr_const = extern struct {
484482
485pub const off_t = i64;483pub const off_t = i64;
486pub const ino_t = u64;484pub const ino_t = u64;
485pub const mode_t = u32;
487486
488/// Renamed to Stat to not conflict with the stat function.
489/// atime, mtime, and ctime have functions to return `timespec`,487/// atime, mtime, and ctime have functions to return `timespec`,
490/// because although this is a POSIX API, the layout and names of488/// because although this is a POSIX API, the layout and names of
491/// the structs are inconsistent across operating systems, and489/// the structs are inconsistent across operating systems, and
492/// in C, macros are used to hide the differences. Here we use490/// in C, macros are used to hide the differences. Here we use
493/// methods to accomplish this.491/// methods to accomplish this.
494pub const Stat = extern struct {492pub const libc_stat = extern struct {
495 dev: u64,493 dev: u64,
496 ino: ino_t,494 ino: ino_t,
497 mode: u32,495 mode: u32,
...@@ -524,6 +522,45 @@ pub const Stat = extern struct {...@@ -524,6 +522,45 @@ pub const Stat = extern struct {
524 }522 }
525};523};
526524
525pub const kernel_stat = extern struct {
526 dev: u32,
527 ino: ino_t,
528 mode: mode_t,
529 nlink: i16,
530
531 uid: u32,
532 gid: u32,
533 rdev: u32,
534
535 size: off_t,
536 atim: isize,
537 mtim: isize,
538 ctim: isize,
539
540 blksize: off_t,
541 blocks: off_t,
542
543 __unused4: [2]isize,
544
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: Stat) timespec {
549 return timespec{.tv_sec=self.atim, .tv_nsec=0};
550 }
551
552 pub fn mtime(self: Stat) timespec {
553 return timespec{.tv_sec=self.mtim, .tv_nsec=0};
554 }
555
556 pub fn ctime(self: Stat) timespec {
557 return timespec{.tv_sec=self.ctim, .tv_nsec=0};
558 }
559};
560
561/// Renamed to Stat to not conflict with the stat function.
562pub const Stat = kernel_stat;
563
527pub const timespec = extern struct {564pub const timespec = extern struct {
528 tv_sec: isize,565 tv_sec: isize,
529 tv_nsec: isize,566 tv_nsec: isize,