| author | |
| committer | |
| log | bb4a532785e8bcd0080eeac291bd3b205279f045 |
| tree | b119dff287b80f7c184da87ac9ec09ae510895f0 |
| parent | 1f9734d1eefa98c4c51ee740717a6cc003a5a7ed |
4 files changed, 19 insertions(+), 12 deletions(-)
CMakeLists.txt+1| ... | ... | @@ -126,6 +126,7 @@ set(ZIG_STD_SRC |
| 126 | 126 | "${CMAKE_SOURCE_DIR}/std/test_runner_libc.zig" |
| 127 | 127 | "${CMAKE_SOURCE_DIR}/std/test_runner_nolibc.zig" |
| 128 | 128 | "${CMAKE_SOURCE_DIR}/std/std.zig" |
| 129 | "${CMAKE_SOURCE_DIR}/std/os.zig" | |
| 129 | 130 | "${CMAKE_SOURCE_DIR}/std/syscall.zig" |
| 130 | 131 | "${CMAKE_SOURCE_DIR}/std/errno.zig" |
| 131 | 132 | "${CMAKE_SOURCE_DIR}/std/rand.zig" |
example/guess_number/main.zig+1| ... | ... | @@ -2,6 +2,7 @@ export executable "guess_number"; |
| 2 | 2 | |
| 3 | 3 | import "std.zig"; |
| 4 | 4 | import "rand.zig"; |
| 5 | import "os.zig"; | |
| 5 | 6 | |
| 6 | 7 | pub fn main(args: [][]u8) -> %void { |
| 7 | 8 | %%stderr.print_str("Welcome to the Guess Number Game in Zig.\n"); |
std/os.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | import "syscall.zig"; | |
| 2 | import "errno.zig"; | |
| 3 | ||
| 4 | pub error SigInterrupt; | |
| 5 | pub error Unexpected; | |
| 6 | ||
| 7 | pub fn os_get_random_bytes(buf: []u8) -> %void { | |
| 8 | const amt_got = getrandom(buf.ptr, buf.len, 0); | |
| 9 | if (amt_got < 0) { | |
| 10 | return switch (-amt_got) { | |
| 11 | EINVAL => unreachable{}, | |
| 12 | EFAULT => unreachable{}, | |
| 13 | EINTR => error.SigInterrupt, | |
| 14 | else => error.Unexpected, | |
| 15 | } | |
| 16 | } | |
| 17 | } |
std/std.zig-12| ... | ... | @@ -160,18 +160,6 @@ pub struct InStream { |
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | pub fn os_get_random_bytes(buf: []u8) -> %void { | |
| 164 | const amt_got = getrandom(buf.ptr, buf.len, 0); | |
| 165 | if (amt_got < 0) { | |
| 166 | return switch (-amt_got) { | |
| 167 | EINVAL => unreachable{}, | |
| 168 | EFAULT => unreachable{}, | |
| 169 | EINTR => error.SigInterrupt, | |
| 170 | else => error.Unexpected, | |
| 171 | } | |
| 172 | } | |
| 173 | } | |
| 174 | ||
| 175 | 163 | #attribute("cold") |
| 176 | 164 | pub fn abort() -> unreachable { |
| 177 | 165 | raise(SIGABRT); |