| author | |
| committer | |
| log | 5687323cd2a759dfdf9533e46e3de8cddb1b55b7 |
| tree | 38bb75a506c0163606064f6dc84951c66e0c1c7e |
| parent | 57830e43ee79dd0ceafc96fdad6c52e73edf1420 |
| parent | 08251fbc544aa03c77d4c311e267689592432282 |
| signature |
Check if /dev/urandom is a character device5 files changed, 125 insertions(+), 0 deletions(-)
std/os.zig+5| ... | ... | @@ -133,6 +133,11 @@ fn getRandomBytesDevURandom(buf: []u8) !void { |
| 133 | 133 | const fd = try openC(c"/dev/urandom", O_RDONLY | O_CLOEXEC, 0); |
| 134 | 134 | defer close(fd); |
| 135 | 135 | |
| 136 | const st = try fstat(fd); | |
| 137 | if (!S_ISCHR(st.mode)) { | |
| 138 | return error.NoDevice; | |
| 139 | } | |
| 140 | ||
| 136 | 141 | const stream = &std.fs.File.openHandle(fd).inStream().stream; |
| 137 | 142 | stream.readNoEof(buf) catch return error.Unexpected; |
| 138 | 143 | } |
std/os/bits/darwin.zig+59| ... | ... | @@ -1116,3 +1116,62 @@ pub const stack_t = extern struct { |
| 1116 | 1116 | ss_size: isize, |
| 1117 | 1117 | ss_flags: i32, |
| 1118 | 1118 | }; |
| 1119 | ||
| 1120 | pub const S_IFMT = 0o170000; | |
| 1121 | ||
| 1122 | pub const S_IFIFO = 0o010000; | |
| 1123 | pub const S_IFCHR = 0o020000; | |
| 1124 | pub const S_IFDIR = 0o040000; | |
| 1125 | pub const S_IFBLK = 0o060000; | |
| 1126 | pub const S_IFREG = 0o100000; | |
| 1127 | pub const S_IFLNK = 0o120000; | |
| 1128 | pub const S_IFSOCK = 0o140000; | |
| 1129 | pub const S_IFWHT = 0o160000; | |
| 1130 | ||
| 1131 | pub const S_ISUID = 0o4000; | |
| 1132 | pub const S_ISGID = 0o2000; | |
| 1133 | pub const S_ISVTX = 0o1000; | |
| 1134 | pub const S_IRWXU = 0o700; | |
| 1135 | pub const S_IRUSR = 0o400; | |
| 1136 | pub const S_IWUSR = 0o200; | |
| 1137 | pub const S_IXUSR = 0o100; | |
| 1138 | pub const S_IRWXG = 0o070; | |
| 1139 | pub const S_IRGRP = 0o040; | |
| 1140 | pub const S_IWGRP = 0o020; | |
| 1141 | pub const S_IXGRP = 0o010; | |
| 1142 | pub const S_IRWXO = 0o007; | |
| 1143 | pub const S_IROTH = 0o004; | |
| 1144 | pub const S_IWOTH = 0o002; | |
| 1145 | pub const S_IXOTH = 0o001; | |
| 1146 | ||
| 1147 | pub fn S_ISFIFO(m: u32) bool { | |
| 1148 | return m & S_IFMT == S_IFIFO; | |
| 1149 | } | |
| 1150 | ||
| 1151 | pub fn S_ISCHR(m: u32) bool { | |
| 1152 | return m & S_IFMT == S_IFCHR; | |
| 1153 | } | |
| 1154 | ||
| 1155 | pub fn S_ISDIR(m: u32) bool { | |
| 1156 | return m & S_IFMT == S_IFDIR; | |
| 1157 | } | |
| 1158 | ||
| 1159 | pub fn S_ISBLK(m: u32) bool { | |
| 1160 | return m & S_IFMT == S_IFBLK; | |
| 1161 | } | |
| 1162 | ||
| 1163 | pub fn S_ISREG(m: u32) bool { | |
| 1164 | return m & S_IFMT == S_IFREG; | |
| 1165 | } | |
| 1166 | ||
| 1167 | pub fn S_ISLNK(m: u32) bool { | |
| 1168 | return m & S_IFMT == S_IFLNK; | |
| 1169 | } | |
| 1170 | ||
| 1171 | pub fn S_ISSOCK(m: u32) bool { | |
| 1172 | return m & S_IFMT == S_IFSOCK; | |
| 1173 | } | |
| 1174 | ||
| 1175 | pub fn S_IWHT(m: u32) bool { | |
| 1176 | return m & S_IFMT == S_IFWHT; | |
| 1177 | } |
std/os/bits/freebsd.zig+59| ... | ... | @@ -876,3 +876,62 @@ pub const stack_t = extern struct { |
| 876 | 876 | ss_size: isize, |
| 877 | 877 | ss_flags: i32, |
| 878 | 878 | }; |
| 879 | ||
| 880 | pub const S_IFMT = 0o170000; | |
| 881 | ||
| 882 | pub const S_IFIFO = 0o010000; | |
| 883 | pub const S_IFCHR = 0o020000; | |
| 884 | pub const S_IFDIR = 0o040000; | |
| 885 | pub const S_IFBLK = 0o060000; | |
| 886 | pub const S_IFREG = 0o100000; | |
| 887 | pub const S_IFLNK = 0o120000; | |
| 888 | pub const S_IFSOCK = 0o140000; | |
| 889 | pub const S_IFWHT = 0o160000; | |
| 890 | ||
| 891 | pub const S_ISUID = 0o4000; | |
| 892 | pub const S_ISGID = 0o2000; | |
| 893 | pub const S_ISVTX = 0o1000; | |
| 894 | pub const S_IRWXU = 0o700; | |
| 895 | pub const S_IRUSR = 0o400; | |
| 896 | pub const S_IWUSR = 0o200; | |
| 897 | pub const S_IXUSR = 0o100; | |
| 898 | pub const S_IRWXG = 0o070; | |
| 899 | pub const S_IRGRP = 0o040; | |
| 900 | pub const S_IWGRP = 0o020; | |
| 901 | pub const S_IXGRP = 0o010; | |
| 902 | pub const S_IRWXO = 0o007; | |
| 903 | pub const S_IROTH = 0o004; | |
| 904 | pub const S_IWOTH = 0o002; | |
| 905 | pub const S_IXOTH = 0o001; | |
| 906 | ||
| 907 | pub fn S_ISFIFO(m: u32) bool { | |
| 908 | return m & S_IFMT == S_IFIFO; | |
| 909 | } | |
| 910 | ||
| 911 | pub fn S_ISCHR(m: u32) bool { | |
| 912 | return m & S_IFMT == S_IFCHR; | |
| 913 | } | |
| 914 | ||
| 915 | pub fn S_ISDIR(m: u32) bool { | |
| 916 | return m & S_IFMT == S_IFDIR; | |
| 917 | } | |
| 918 | ||
| 919 | pub fn S_ISBLK(m: u32) bool { | |
| 920 | return m & S_IFMT == S_IFBLK; | |
| 921 | } | |
| 922 | ||
| 923 | pub fn S_ISREG(m: u32) bool { | |
| 924 | return m & S_IFMT == S_IFREG; | |
| 925 | } | |
| 926 | ||
| 927 | pub fn S_ISLNK(m: u32) bool { | |
| 928 | return m & S_IFMT == S_IFLNK; | |
| 929 | } | |
| 930 | ||
| 931 | pub fn S_ISSOCK(m: u32) bool { | |
| 932 | return m & S_IFMT == S_IFSOCK; | |
| 933 | } | |
| 934 | ||
| 935 | pub fn S_IWHT(m: u32) bool { | |
| 936 | return m & S_IFMT == S_IFWHT; | |
| 937 | } |
std/os/darwin.zig+1| ... | ... | @@ -5,3 +5,4 @@ pub const is_the_target = switch (builtin.os) { |
| 5 | 5 | else => false, |
| 6 | 6 | }; |
| 7 | 7 | pub usingnamespace std.c; |
| 8 | pub usingnamespace @import("bits.zig"); | |
| \ No newline at end of file |
std/os/freebsd.zig+1| ... | ... | @@ -2,3 +2,4 @@ const std = @import("../std.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | pub const is_the_target = builtin.os == .freebsd; |
| 4 | 4 | pub usingnamespace std.c; |
| 5 | pub usingnamespace @import("bits.zig"); | |
| \ No newline at end of file |