authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-12-28 22:16:27 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-12-28 22:16:27 -08:00
log6d281c3091979fcad6336112132a3930d7ef86fc
treee33227d8b8d7b6df25005c5421760193fe8fd0ac
parent67e61e7f59305835b3846e530b35c0823b3678a6

File.Stat: remove .kind field and make it a method


1 files changed, 25 insertions(+), 2 deletions(-)

File.zig+25-2
...@@ -90,7 +90,6 @@ pub const Stat = struct {...@@ -90,7 +90,6 @@ pub const Stat = struct {
90 inode: INode,90 inode: INode,
91 size: u64,91 size: u64,
92 mode: Mode,92 mode: Mode,
93 kind: void, //Kind,
94 /// Last access time in nanoseconds, relative to UTC 1970-01-01.93 /// Last access time in nanoseconds, relative to UTC 1970-01-01.
95 atime: i128,94 atime: i128,
96 /// Last modification time in nanoseconds, relative to UTC 1970-01-01.95 /// Last modification time in nanoseconds, relative to UTC 1970-01-01.
...@@ -120,6 +119,23 @@ pub const Stat = struct {...@@ -120,6 +119,23 @@ pub const Stat = struct {
120 };119 };
121 }120 }
122 }121 }
122
123 pub fn kind(self: Stat) Kind {
124 if (os == .linux) {
125 const m = self.mode & sys_linux.S.IFMT;
126 switch (m) {
127 sys_linux.S.IFBLK => return .block_device,
128 sys_linux.S.IFCHR => return .character_device,
129 sys_linux.S.IFIFO => return .named_pipe,
130 sys_linux.S.IFREG => return .file,
131 sys_linux.S.IFDIR => return .directory,
132 sys_linux.S.IFLNK => return .symlink,
133 sys_linux.S.IFSOCK => return .unix_socket,
134 else => {},
135 }
136 return .unknown;
137 }
138 }
123};139};
124140
125pub const INode = switch (builtin.target.os.tag) {141pub const INode = switch (builtin.target.os.tag) {
...@@ -135,5 +151,12 @@ pub const Mode = switch (builtin.target.os.tag) {...@@ -135,5 +151,12 @@ pub const Mode = switch (builtin.target.os.tag) {
135};151};
136152
137pub const Kind = enum {153pub const Kind = enum {
138 //154 block_device,
155 character_device,
156 named_pipe,
157 file,
158 directory,
159 symlink,
160 unix_socket,
161 unknown,
139};162};