| author | |
| committer | |
| log | 37ecaae6390d238dce21ef4b97e6994dd229c2c3 |
| tree | 71fd2226964dfa43a17fde62c4d896bfdd5a2c82 |
| parent | 47c932f8960e361282269202dc8ad7e63e3a06eb |
| signature |
6 files changed, 20 insertions(+), 8 deletions(-)
lib/std/fmt.zig+12-2| ... | ... | @@ -602,9 +602,19 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintErro |
| 602 | 602 | return w.buffered(); |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | /// Deprecated in favor of `bufPrintSentinel` | |
| 605 | 606 | pub fn bufPrintZ(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![:0]u8 { |
| 606 | const result = try bufPrint(buf, fmt ++ "\x00", args); | |
| 607 | return result[0 .. result.len - 1 :0]; | |
| 607 | return try bufPrintSentinel(buf, fmt, args, 0); | |
| 608 | } | |
| 609 | ||
| 610 | pub fn bufPrintSentinel( | |
| 611 | buf: []u8, | |
| 612 | comptime fmt: []const u8, | |
| 613 | args: anytype, | |
| 614 | comptime sentinel: u8, | |
| 615 | ) BufPrintError![:sentinel]u8 { | |
| 616 | const result = try bufPrint(buf, fmt ++ [_]u8{sentinel}, args); | |
| 617 | return result[0 .. result.len - 1 :sentinel]; | |
| 608 | 618 | } |
| 609 | 619 | |
| 610 | 620 | /// Count the characters needed for format. |
lib/std/fs.zig+2-1| ... | ... | @@ -616,9 +616,10 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { |
| 616 | 616 | var path_it = mem.tokenizeScalar(u8, PATH, path.delimiter); |
| 617 | 617 | while (path_it.next()) |a_path| { |
| 618 | 618 | var resolved_path_buf: [max_path_bytes - 1:0]u8 = undefined; |
| 619 | const resolved_path = std.fmt.bufPrintZ(&resolved_path_buf, "{s}/{s}", .{ | |
| 619 | const resolved_path = std.fmt.bufPrintSentinel(&resolved_path_buf, "{s}/{s}", .{ | |
| 620 | 620 | a_path, |
| 621 | 621 | std.os.argv[0], |
| 622 | 0, | |
| 622 | 623 | }) catch continue; |
| 623 | 624 | |
| 624 | 625 | var real_path_buf: [max_path_bytes]u8 = undefined; |
lib/std/meta.zig+1-1| ... | ... | @@ -935,7 +935,7 @@ fn CreateUniqueTuple(comptime N: comptime_int, comptime types: [N]type) type { |
| 935 | 935 | @setEvalBranchQuota(10_000); |
| 936 | 936 | var num_buf: [128]u8 = undefined; |
| 937 | 937 | tuple_fields[i] = .{ |
| 938 | .name = std.fmt.bufPrintZ(&num_buf, "{d}", .{i}) catch unreachable, | |
| 938 | .name = std.fmt.bufPrintSentinel(&num_buf, "{d}", .{i}, 0) catch unreachable, | |
| 939 | 939 | .type = T, |
| 940 | 940 | .default_value_ptr = null, |
| 941 | 941 | .is_comptime = false, |
lib/std/os.zig+2-2| ... | ... | @@ -132,7 +132,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix. |
| 132 | 132 | }, |
| 133 | 133 | .linux, .serenity => { |
| 134 | 134 | var procfs_buf: ["/proc/self/fd/-2147483648\x00".len]u8 = undefined; |
| 135 | const proc_path = std.fmt.bufPrintZ(procfs_buf[0..], "/proc/self/fd/{d}", .{fd}) catch unreachable; | |
| 135 | const proc_path = std.fmt.bufPrintSentinel(procfs_buf[0..], "/proc/self/fd/{d}", .{fd}, 0) catch unreachable; | |
| 136 | 136 | |
| 137 | 137 | const target = posix.readlinkZ(proc_path, out_buffer) catch |err| { |
| 138 | 138 | switch (err) { |
| ... | ... | @@ -149,7 +149,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix. |
| 149 | 149 | }, |
| 150 | 150 | .solaris, .illumos => { |
| 151 | 151 | var procfs_buf: ["/proc/self/path/-2147483648\x00".len]u8 = undefined; |
| 152 | const proc_path = std.fmt.bufPrintZ(procfs_buf[0..], "/proc/self/path/{d}", .{fd}) catch unreachable; | |
| 152 | const proc_path = std.fmt.bufPrintSentinel(procfs_buf[0..], "/proc/self/path/{d}", .{fd}, 0) catch unreachable; | |
| 153 | 153 | |
| 154 | 154 | const target = posix.readlinkZ(proc_path, out_buffer) catch |err| switch (err) { |
| 155 | 155 | error.UnsupportedReparsePointType => unreachable, |
lib/std/posix.zig+1-1| ... | ... | @@ -497,7 +497,7 @@ fn fchmodat2(dirfd: fd_t, path: []const u8, mode: mode_t, flags: u32) FChmodAtEr |
| 497 | 497 | return error.OperationNotSupported; |
| 498 | 498 | |
| 499 | 499 | var procfs_buf: ["/proc/self/fd/-2147483648\x00".len]u8 = undefined; |
| 500 | const proc_path = std.fmt.bufPrintZ(procfs_buf[0..], "/proc/self/fd/{d}", .{pathfd}) catch unreachable; | |
| 500 | const proc_path = std.fmt.bufPrintSentinel(procfs_buf[0..], "/proc/self/fd/{d}", .{pathfd}, 0) catch unreachable; | |
| 501 | 501 | while (true) { |
| 502 | 502 | const res = system.chmod(proc_path, mode); |
| 503 | 503 | switch (errno(res)) { |
lib/std/process/Child.zig+2-1| ... | ... | @@ -1320,10 +1320,11 @@ fn windowsMakeAsyncPipe(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *cons |
| 1320 | 1320 | const pipe_path = blk: { |
| 1321 | 1321 | var tmp_buf: [128]u8 = undefined; |
| 1322 | 1322 | // Forge a random path for the pipe. |
| 1323 | const pipe_path = std.fmt.bufPrintZ( | |
| 1323 | const pipe_path = std.fmt.bufPrintSentinel( | |
| 1324 | 1324 | &tmp_buf, |
| 1325 | 1325 | "\\\\.\\pipe\\zig-childprocess-{d}-{d}", |
| 1326 | 1326 | .{ windows.GetCurrentProcessId(), pipe_name_counter.fetchAdd(1, .monotonic) }, |
| 1327 | 0, | |
| 1327 | 1328 | ) catch unreachable; |
| 1328 | 1329 | const len = std.unicode.wtf8ToWtf16Le(&tmp_bufw, pipe_path) catch unreachable; |
| 1329 | 1330 | tmp_bufw[len] = 0; |