authorgravatar for euantorano@gmail.comEuan Torano <euantorano@gmail.com> 2019-08-02 15:44:58+01:00
committergravatar for euantorano@gmail.comEuan Torano <euantorano@gmail.com> 2019-08-02 15:55:56+01:00
log1583efda69622b9c7809419a4320f4e8ea6fd4e3
tree44676ccd2dd644c035115b259a58543d137fbbb8
parentc0c228b758150e017185dc280ef020ec3b7efdcf

Fix call to S_ISCHR and implement for Mac


3 files changed, 53 insertions(+), 2 deletions(-)

std/os.zig+2-2
...@@ -134,8 +134,8 @@ fn getRandomBytesDevURandom(buf: []u8) !void {...@@ -134,8 +134,8 @@ fn getRandomBytesDevURandom(buf: []u8) !void {
134 defer close(fd);134 defer close(fd);
135135
136 const st = try fstat(fd);136 const st = try fstat(fd);
137 if (!S_ISCHR(st.mode)) {137 if (!system.S_ISCHR(st.mode)) {
138 return OpenError.Unexpected;138 return error.Unexpected;
139 }139 }
140140
141 const stream = &std.fs.File.openHandle(fd).inStream().stream;141 const stream = &std.fs.File.openHandle(fd).inStream().stream;
std/os/bits/darwin.zig+50
...@@ -1116,3 +1116,53 @@ pub const stack_t = extern struct {...@@ -1116,3 +1116,53 @@ pub const stack_t = extern struct {
1116 ss_size: isize,1116 ss_size: isize,
1117 ss_flags: i32,1117 ss_flags: i32,
1118};1118};
1119
1120pub const S_IFMT = 0o170000;
1121
1122pub const S_IFIFO = 0o010000;
1123pub const S_IFCHR = 0o020000;
1124pub const S_IFDIR = 0o040000;
1125pub const S_IFBLK = 0o060000;
1126pub const S_IFREG = 0o100000;
1127pub const S_IFLNK = 0o120000;
1128pub const S_IFSOCK = 0o140000;
1129pub const S_IFWHT = 0o160000;
1130
1131pub const S_ISUID = 0o4000;
1132pub const S_ISGID = 0o2000;
1133pub const S_ISVTX = 0o1000;
1134pub const S_IRUSR = 0o400;
1135pub const S_IWUSR = 0o200;
1136pub const S_IXUSR = 0o100;
1137
1138pub fn S_ISFIFO(m: u32) bool {
1139 return m & S_IFMT == S_IFIFO;
1140}
1141
1142pub fn S_ISCHR(m: u32) bool {
1143 return m & S_IFMT == S_IFCHR;
1144}
1145
1146pub fn S_ISDIR(m: u32) bool {
1147 return m & S_IFMT == S_IFDIR;
1148}
1149
1150pub fn S_ISBLK(m: u32) bool {
1151 return m & S_IFMT == S_IFBLK;
1152}
1153
1154pub fn S_ISREG(m: u32) bool {
1155 return m & S_IFMT == S_IFREG;
1156}
1157
1158pub fn S_ISLNK(m: u32) bool {
1159 return m & S_IFMT == S_IFLNK;
1160}
1161
1162pub fn S_ISSOCK(m: u32) bool {
1163 return m & S_IFMT == S_IFSOCK;
1164}
1165
1166pub fn S_IWHT(m: u32) bool {
1167 return m & S_IFMT == S_IFWHT;
1168}
std/os/darwin.zig+1
...@@ -5,3 +5,4 @@ pub const is_the_target = switch (builtin.os) {...@@ -5,3 +5,4 @@ pub const is_the_target = switch (builtin.os) {
5 else => false,5 else => false,
6};6};
7pub usingnamespace std.c;7pub usingnamespace std.c;
8pub usingnamespace @import("bits.zig");
\ No newline at end of file