diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-01-05 14:50:02 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-05 14:50:02 -0500 |
| commit | a0ca34979ea5ff9be0d353f539e7c86dedbf8693 (patch) | |
| tree | e81c0dbbc2b7b81ce1d6f46b79ee781e31326ebc /lib/std/fs.zig | |
| parent | 2e5342512f32384777ebcb0bf3dcb177b9380080 (diff) | |
| parent | 242f5d10d57eb9239e7a89d4e705fc05785abe7c (diff) | |
| download | zig-a0ca34979ea5ff9be0d353f539e7c86dedbf8693.tar.gz zig-a0ca34979ea5ff9be0d353f539e7c86dedbf8693.zip | |
Merge pull request #4053 from ziglang/test-run-translated-c
add test harness for "run translated C" tests
Diffstat (limited to 'lib/std/fs.zig')
| -rw-r--r-- | lib/std/fs.zig | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/std/fs.zig b/lib/std/fs.zig index ea62086f59..540d5f1a1a 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -37,8 +37,11 @@ pub const MAX_PATH_BYTES = switch (builtin.os) { else => @compileError("Unsupported OS"), }; -// here we replace the standard +/ with -_ so that it can be used in a file name -const b64_fs_encoder = base64.Base64Encoder.init("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", base64.standard_pad_char); +/// Base64, replacing the standard `+/` with `-_` so that it can be used in a file name on any filesystem. +pub const base64_encoder = base64.Base64Encoder.init( + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", + base64.standard_pad_char, +); /// TODO remove the allocator requirement from this API pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) !void { @@ -58,7 +61,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: tmp_path[dirname.len] = path.sep; while (true) { try crypto.randomBytes(rand_buf[0..]); - b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], &rand_buf); + base64_encoder.encode(tmp_path[dirname.len + 1 ..], &rand_buf); if (symLink(existing_path, tmp_path)) { return rename(tmp_path, new_path); @@ -227,10 +230,10 @@ pub const AtomicFile = struct { while (true) { try crypto.randomBytes(rand_buf[0..]); - b64_fs_encoder.encode(tmp_path_slice[dirname_component_len..tmp_path_len], &rand_buf); + base64_encoder.encode(tmp_path_slice[dirname_component_len..tmp_path_len], &rand_buf); const file = my_cwd.createFileC( - tmp_path_slice, + tmp_path_slice, .{ .mode = mode, .exclusive = true }, ) catch |err| switch (err) { error.PathAlreadyExists => continue, |
