authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-30 03:54:49 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-30 03:54:49 -07:00
logea93df8f7bcd07e2c5a74b7d17e03b12ae659dd7
tree44b4c6792c52eb5e95d25741c2f3df0a058596c1
parentce608cf7a06b271f7ada3dd6763199701cf2f555
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add getrandom


2 files changed, 14 insertions(+), 0 deletions(-)

mod.zig+13
...@@ -2749,6 +2749,7 @@ pub const libc = struct {...@@ -2749,6 +2749,7 @@ pub const libc = struct {
2749 pub extern fn sendfile(out_fd: c_int, in_fd: c_int, offset: ?*const off_t, count: usize) isize;2749 pub extern fn sendfile(out_fd: c_int, in_fd: c_int, offset: ?*const off_t, count: usize) isize;
2750 pub extern fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) c_int;2750 pub extern fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) c_int;
2751 pub extern fn sched_getaffinity(pid: pid_t, cpusetsize: usize, mask: *cpu_set_t) c_int;2751 pub extern fn sched_getaffinity(pid: pid_t, cpusetsize: usize, mask: *cpu_set_t) c_int;
2752 pub extern fn getrandom(buf: [*]u8, size: usize, flags: c_uint) isize;
2752};2753};
27532754
2754pub const clock_t = c_long;2755pub const clock_t = c_long;
...@@ -3199,6 +3200,12 @@ pub const DT = enum(u8) {...@@ -3199,6 +3200,12 @@ pub const DT = enum(u8) {
3199 WHT = 14,3200 WHT = 14,
3200};3201};
32013202
3203pub const GRND = struct {
3204 pub const NONBLOCK = 0x0001;
3205 pub const RANDOM = 0x0002;
3206 pub const INSECURE = 0x0004;
3207};
3208
3202pub fn getpid() pid_t {3209pub fn getpid() pid_t {
3203 return libc.getpid();3210 return libc.getpid();
3204}3211}
...@@ -3486,3 +3493,9 @@ pub fn mkdtemp(template: [*:0]u8) ![*:0]u8 {...@@ -3486,3 +3493,9 @@ pub fn mkdtemp(template: [*:0]u8) ![*:0]u8 {
3486 if (rc == null) return errno.fromInt(errno.fromLibC());3493 if (rc == null) return errno.fromInt(errno.fromLibC());
3487 return rc.?;3494 return rc.?;
3488}3495}
3496pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 {
3497 const rc = libc.getrandom(buf.ptr, buf.len, flags);
3498 if (rc == -1) return errno.fromInt(errno.fromLibC());
3499 std.debug.assert(rc >= 0);
3500 return buf[0..@intCast(rc)];
3501}
test.zig+1
...@@ -59,4 +59,5 @@ test {...@@ -59,4 +59,5 @@ test {
59 _ = &linux.pthread_cond_signal;59 _ = &linux.pthread_cond_signal;
60 _ = &linux.pthread_cond_broadcast;60 _ = &linux.pthread_cond_broadcast;
61 _ = &linux.mkdtemp;61 _ = &linux.mkdtemp;
62 _ = &linux.getrandom;
62}63}