| author | |
| committer | |
| log | 577b57784ae70a85f5f4fef37e749687d0e9b6b0 |
| tree | 469a989c36cec6e6baf5663dc52f55581102f469 |
| parent | 71548824237174aa5310c339c3161eae1623cf73 |
4 files changed, 10 insertions(+), 11 deletions(-)
lib/std/base64.zig+4-4| ... | ... | @@ -38,8 +38,8 @@ pub const Base64Encoder = struct { |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /// dest.len must be what you get from ::calcSize. |
| 41 | pub fn encode(encoder: *const Base64Encoder, dest: []u8, source: []const u8) void { | |
| 42 | assert(dest.len == Base64Encoder.calcSize(source.len)); | |
| 41 | pub fn encode(encoder: *const Base64Encoder, dest: []u8, source: []const u8) []const u8 { | |
| 42 | assert(dest.len >= Base64Encoder.calcSize(source.len)); | |
| 43 | 43 | |
| 44 | 44 | var i: usize = 0; |
| 45 | 45 | var out_index: usize = 0; |
| ... | ... | @@ -78,6 +78,7 @@ pub const Base64Encoder = struct { |
| 78 | 78 | dest[out_index] = encoder.pad_char; |
| 79 | 79 | out_index += 1; |
| 80 | 80 | } |
| 81 | return dest[0..out_index]; | |
| 81 | 82 | } |
| 82 | 83 | }; |
| 83 | 84 | |
| ... | ... | @@ -398,8 +399,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void |
| 398 | 399 | // Base64Encoder |
| 399 | 400 | { |
| 400 | 401 | var buffer: [0x100]u8 = undefined; |
| 401 | var encoded = buffer[0..Base64Encoder.calcSize(expected_decoded.len)]; | |
| 402 | standard_encoder.encode(encoded, expected_decoded); | |
| 402 | const encoded = standard_encoder.encode(&buffer, expected_decoded); | |
| 403 | 403 | testing.expectEqualSlices(u8, expected_encoded, encoded); |
| 404 | 404 | } |
| 405 | 405 |
lib/std/build/write_file.zig+1-1| ... | ... | @@ -72,7 +72,7 @@ pub const WriteFileStep = struct { |
| 72 | 72 | var digest: [48]u8 = undefined; |
| 73 | 73 | hash.final(&digest); |
| 74 | 74 | var hash_basename: [64]u8 = undefined; |
| 75 | fs.base64_encoder.encode(&hash_basename, &digest); | |
| 75 | _ = fs.base64_encoder.encode(&hash_basename, &digest); | |
| 76 | 76 | self.output_dir = try fs.path.join(self.builder.allocator, &[_][]const u8{ |
| 77 | 77 | self.builder.cache_root, |
| 78 | 78 | "o", |
lib/std/fs.zig+4-5| ... | ... | @@ -83,7 +83,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: |
| 83 | 83 | tmp_path[dirname.len] = path.sep; |
| 84 | 84 | while (true) { |
| 85 | 85 | crypto.random.bytes(rand_buf[0..]); |
| 86 | base64_encoder.encode(tmp_path[dirname.len + 1 ..], &rand_buf); | |
| 86 | _ = base64_encoder.encode(tmp_path[dirname.len + 1 ..], &rand_buf); | |
| 87 | 87 | |
| 88 | 88 | if (cwd().symLink(existing_path, tmp_path, .{})) { |
| 89 | 89 | return cwd().rename(tmp_path, new_path); |
| ... | ... | @@ -153,15 +153,14 @@ pub const AtomicFile = struct { |
| 153 | 153 | ) InitError!AtomicFile { |
| 154 | 154 | var rand_buf: [RANDOM_BYTES]u8 = undefined; |
| 155 | 155 | var tmp_path_buf: [TMP_PATH_LEN:0]u8 = undefined; |
| 156 | // TODO: should be able to use TMP_PATH_LEN here. | |
| 157 | tmp_path_buf[base64.Base64Encoder.calcSize(RANDOM_BYTES)] = 0; | |
| 158 | 156 | |
| 159 | 157 | while (true) { |
| 160 | 158 | crypto.random.bytes(rand_buf[0..]); |
| 161 | base64_encoder.encode(&tmp_path_buf, &rand_buf); | |
| 159 | const tmp_path = base64_encoder.encode(&tmp_path_buf, &rand_buf); | |
| 160 | tmp_path_buf[tmp_path.len] = 0; | |
| 162 | 161 | |
| 163 | 162 | const file = dir.createFile( |
| 164 | &tmp_path_buf, | |
| 163 | tmp_path, | |
| 165 | 164 | .{ .mode = mode, .exclusive = true }, |
| 166 | 165 | ) catch |err| switch (err) { |
| 167 | 166 | error.PathAlreadyExists => continue, |
lib/std/testing.zig+1-1| ... | ... | @@ -305,7 +305,7 @@ pub fn tmpDir(opts: std.fs.Dir.OpenDirOptions) TmpDir { |
| 305 | 305 | var random_bytes: [TmpDir.random_bytes_count]u8 = undefined; |
| 306 | 306 | std.crypto.random.bytes(&random_bytes); |
| 307 | 307 | var sub_path: [TmpDir.sub_path_len]u8 = undefined; |
| 308 | std.fs.base64_encoder.encode(&sub_path, &random_bytes); | |
| 308 | _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes); | |
| 309 | 309 | |
| 310 | 310 | var cwd = getCwdOrWasiPreopen(); |
| 311 | 311 | var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch |