| ... | @@ -46,9 +46,12 @@ pub fn munmap(region: []const u8) void { | ... | @@ -46,9 +46,12 @@ pub fn munmap(region: []const u8) void { |
| 46 | } | 46 | } |
| 47 | | 47 | |
| 48 | pub fn mkdtemp() !Dir { | 48 | pub fn mkdtemp() !Dir { |
| 49 | var template = "/tmp/tmp.XXXXXX\x00".*; | 49 | var template = "/tmp/tmp.XXXXXXXXXX\x00".*; |
| 50 | const path_p = try sys.mkdtemp(template[0 .. template.len - 1 :0].ptr); | 50 | const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
| 51 | const path = std.mem.sliceTo(path_p, 0); | 51 | var buf: [10]u8 = @splat(0); |
| 52 | std.log.debug("path: {s}", .{path}); | 52 | const rand = try sys.getrandom(&buf, 0); |
| 53 | return cwd().openDir(path, .{}); | 53 | if (rand.len != 10) return error.EAGAIN; |
| | 54 | for (template[9..][0..10], rand) |*a, b| a.* = letters[b % 62]; |
| | 55 | const path = template[0 .. template.len - 1 :0]; |
| | 56 | return cwd().makeOpenPath(path, .{}); |
| 54 | } | 57 | } |