authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-23 19:24:41-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-23 19:24:41-07:00
log95b36afadfe436856757013206db6c7048ff69c2
treec85733e484e5a377aee74fabbbb2bfd7269764bf
parent0e6c256cd96af224511210d877acef60ac07484f
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

use nio.randomBytes instead of sys.getrandom directly


1 files changed, 2 insertions(+), 5 deletions(-)

nfs.zig+2-5
...@@ -57,8 +57,7 @@ pub fn munmap(region: []const u8) void {...@@ -57,8 +57,7 @@ pub fn munmap(region: []const u8) void {
57pub fn mkdtemp() !Dir {57pub fn mkdtemp() !Dir {
58 var template = "/tmp/tmp.XXXXXXXXXX\x00".*;58 var template = "/tmp/tmp.XXXXXXXXXX\x00".*;
59 const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";59 const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
60 var buf: [10]u8 = @splat(0);60 const rand = nio.randomBytes(10);
61 const rand = try sys.getrandom(&buf, 0);
62 if (rand.len != 10) return error.EAGAIN;61 if (rand.len != 10) return error.EAGAIN;
63 for (template[9..][0..10], rand) |*a, b| a.* = letters[b % 62];62 for (template[9..][0..10], rand) |*a, b| a.* = letters[b % 62];
64 const path = template[0 .. template.len - 1 :0];63 const path = template[0 .. template.len - 1 :0];
...@@ -68,9 +67,7 @@ pub fn mkdtemp() !Dir {...@@ -68,9 +67,7 @@ pub fn mkdtemp() !Dir {
68pub fn mktemp(flags: Dir.CreateFlags) !File {67pub fn mktemp(flags: Dir.CreateFlags) !File {
69 var template = "/tmp/tmp.XXXXXXXXXX\x00".*;68 var template = "/tmp/tmp.XXXXXXXXXX\x00".*;
70 const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";69 const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
71 var buf: [10]u8 = @splat(0);70 const rand = nio.randomBytes(10);
72 const rand = try sys.getrandom(&buf, 0);
73 if (rand.len != 10) return error.EAGAIN;
74 for (template[9..][0..10], rand) |*a, b| a.* = letters[b % 62];71 for (template[9..][0..10], rand) |*a, b| a.* = letters[b % 62];
75 const path = template[0 .. template.len - 1 :0];72 const path = template[0 .. template.len - 1 :0];
76 return cwd().createFile(path, flags);73 return cwd().createFile(path, flags);