| ... | ... | @@ -90,7 +90,6 @@ pub const Stat = struct { |
| 90 | 90 | inode: INode, |
| 91 | 91 | size: u64, |
| 92 | 92 | mode: Mode, |
| 93 | | kind: void, //Kind, |
| 94 | 93 | /// Last access time in nanoseconds, relative to UTC 1970-01-01. |
| 95 | 94 | atime: i128, |
| 96 | 95 | /// Last modification time in nanoseconds, relative to UTC 1970-01-01. |
| ... | ... | @@ -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 | }; |
| 124 | 140 | |
| 125 | 141 | pub const INode = switch (builtin.target.os.tag) { |
| ... | ... | @@ -135,5 +151,12 @@ pub const Mode = switch (builtin.target.os.tag) { |
| 135 | 151 | }; |
| 136 | 152 | |
| 137 | 153 | pub 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 | }; |