From bb4a532785e8bcd0080eeac291bd3b205279f045 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 4 Feb 2016 01:00:54 -0700 Subject: move os_get_random_bytes to os.zig --- std/os.zig | 17 +++++++++++++++++ std/std.zig | 12 ------------ 2 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 std/os.zig (limited to 'std') diff --git a/std/os.zig b/std/os.zig new file mode 100644 index 0000000000..b82ab0c048 --- /dev/null +++ b/std/os.zig @@ -0,0 +1,17 @@ +import "syscall.zig"; +import "errno.zig"; + +pub error SigInterrupt; +pub error Unexpected; + +pub fn os_get_random_bytes(buf: []u8) -> %void { + const amt_got = getrandom(buf.ptr, buf.len, 0); + if (amt_got < 0) { + return switch (-amt_got) { + EINVAL => unreachable{}, + EFAULT => unreachable{}, + EINTR => error.SigInterrupt, + else => error.Unexpected, + } + } +} diff --git a/std/std.zig b/std/std.zig index d628692ae0..70753c0c82 100644 --- a/std/std.zig +++ b/std/std.zig @@ -160,18 +160,6 @@ pub struct InStream { } } -pub fn os_get_random_bytes(buf: []u8) -> %void { - const amt_got = getrandom(buf.ptr, buf.len, 0); - if (amt_got < 0) { - return switch (-amt_got) { - EINVAL => unreachable{}, - EFAULT => unreachable{}, - EINTR => error.SigInterrupt, - else => error.Unexpected, - } - } -} - #attribute("cold") pub fn abort() -> unreachable { raise(SIGABRT); -- cgit v1.2.3