| ... | @@ -55,3 +55,14 @@ pub fn mkdtemp() !Dir { | ... | @@ -55,3 +55,14 @@ pub fn mkdtemp() !Dir { |
| 55 | const path = template[0 .. template.len - 1 :0]; | 55 | const path = template[0 .. template.len - 1 :0]; |
| 56 | return cwd().makeOpenPath(path, .{}); | 56 | return cwd().makeOpenPath(path, .{}); |
| 57 | } | 57 | } |
| | 58 | |
| | 59 | pub fn mktemp(flags: Dir.CreateFlags) !File { |
| | 60 | var template = "/tmp/tmp.XXXXXXXXXX\x00".*; |
| | 61 | const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
| | 62 | var buf: [10]u8 = @splat(0); |
| | 63 | const rand = try sys.getrandom(&buf, 0); |
| | 64 | if (rand.len != 10) return error.EAGAIN; |
| | 65 | for (template[9..][0..10], rand) |*a, b| a.* = letters[b % 62]; |
| | 66 | const path = template[0 .. template.len - 1 :0]; |
| | 67 | return cwd().createFile(path, flags); |
| | 68 | } |