From d5c37d9122240fe95d308fbe15874e14dd786c5a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 21 Oct 2026 14:38:16 -0300 Subject: Build with Zig 0.17 --- src/post.zig | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'src/post.zig') diff --git a/src/post.zig b/src/post.zig index 641970d..1355b56 100644 --- a/src/post.zig +++ b/src/post.zig @@ -191,7 +191,7 @@ fn socketNonblocking() !i32 { /// directly. fn rawErrno(rc: isize) linux.E { const n: usize = if (rc < 0 and -rc < 4096) @intCast(-rc) else 0; - return @enumFromInt(n); + return @fromBackingInt(@intCast(n)); } pub const DialError = error{ @@ -329,7 +329,7 @@ pub fn post(io: Io, env: Env, name: []const u8, backlog: u31, path_buf: []u8) Po const parent = dir_path[0 .. dir_path.len - "/9p".len]; const serial = temp_serial.fetchAdd(1, .monotonic); var tmp_buf: [std.fs.max_path_bytes]u8 = undefined; - const tmp = std.fmt.bufPrintZ(&tmp_buf, "{s}/.post.sock.{d}.{d}", .{ parent, linux.getpid(), serial }) catch return error.NoSpace; + const tmp = std.fmt.bufPrintSentinel(&tmp_buf, "{s}/.post.sock.{d}.{d}", .{ parent, linux.getpid(), serial }, 0) catch return error.NoSpace; var attempts: usize = 0; var saw_not_socket = false; claim: while (attempts < post_attempts) : (attempts += 1) { @@ -456,7 +456,7 @@ fn claimName(io: Io, registry_dir: [:0]const u8, path: [:0]const u8, sock_tmp: [ // registry directory, so no listing ever sees it. const dummy_serial = temp_serial.fetchAdd(1, .monotonic); var dummy_buf: [std.fs.max_path_bytes]u8 = undefined; - const dummy = std.fmt.bufPrintZ(&dummy_buf, "{s}/.post.tmp.{d}.{d}", .{ parent, linux.getpid(), dummy_serial }) catch return .retry; + const dummy = std.fmt.bufPrintSentinel(&dummy_buf, "{s}/.post.tmp.{d}.{d}", .{ parent, linux.getpid(), dummy_serial }, 0) catch return .retry; var dummy_file = Io.Dir.createFileAbsolute(io, dummy, .{ .exclusive = true, .truncate = false }) catch return .retry; dummy_file.close(io); const dummy_st = Io.Dir.statFile(.cwd(), io, dummy, .{}) catch { @@ -567,7 +567,7 @@ fn swapBack(path: [:0]const u8, tmp: [:0]const u8) isize { /// serialization. fn lockStaleRemoval(registry_dir: [:0]const u8) i32 { var buf: [std.fs.max_path_bytes]u8 = undefined; - const lock_path = std.fmt.bufPrintZ(&buf, "{s}/.post.lock", .{registry_dir[0 .. registry_dir.len - "/9p".len]}) catch return -1; + const lock_path = std.fmt.bufPrintSentinel(&buf, "{s}/.post.lock", .{registry_dir[0 .. registry_dir.len - "/9p".len]}, 0) catch return -1; const fd: isize = @bitCast(linux.open(lock_path.ptr, .{ .ACCMODE = .RDWR, .CREAT = true, .CLOEXEC = true }, 0o600)); if (rawErrno(fd) != .SUCCESS) return -1; const lfd: i32 = @intCast(fd); @@ -709,7 +709,7 @@ const Scratch = struct { s.dir = testing.tmpDir(.{}); errdefer s.dir.cleanup(); const len = try s.dir.dir.realPath(io, &s.path_buf); - const value = try std.fmt.bufPrintZ(&s.env_buf, "XDG_RUNTIME_DIR={s}", .{s.path_buf[0..len]}); + const value = try std.fmt.bufPrintSentinel(&s.env_buf, "XDG_RUNTIME_DIR={s}", .{s.path_buf[0..len]}, 0); s.env[0] = @ptrCast(value.ptr); s.env[1] = null; } @@ -735,7 +735,7 @@ test "post getenv: the block is scanned, keys match whole" { test "post legalName: traversal, empties and the socket budget" { try testing.expect(legalName("demo")); try testing.expect(legalName("...")); - try testing.expect(legalName("a" ** max_name_len)); + try testing.expect(legalName(&@as([max_name_len]u8, @splat('a')))); // Empty and dot names are not postable. try testing.expect(!legalName("")); try testing.expect(!legalName(".")); @@ -746,8 +746,8 @@ test "post legalName: traversal, empties and the socket budget" { try testing.expect(!legalName("..\x00..")); try testing.expect(!legalName("a\x00b")); // The name must fit a Unix socket path. - try testing.expect(!legalName("a" ** (max_name_len + 1))); - try testing.expect(!legalName("a" ** 255)); + try testing.expect(!legalName(&@as([max_name_len + 1]u8, @splat('a')))); + try testing.expect(!legalName(&@as([255]u8, @splat('a')))); } test "post registryPath: unset XDG is refused, no /tmp fallback" { @@ -773,7 +773,7 @@ test "post registryPath: shape, budget and caller buffer" { try testing.expectError(error.IllegalName, registryPath(e, "..", &buf)); // The 108-byte sockaddr budget, checked against the real prefix. const long_env = [_:null]?[*:0]const u8{"XDG_RUNTIME_DIR=/tmp/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}; - const name = "n" ** max_name_len; // legal against the 32-byte XDG budget + const name: []const u8 = &@as([max_name_len]u8, @splat('n')); // legal against the 32-byte XDG budget try testing.expectError(error.NameTooLong, registryPath(@ptrCast(&long_env), name, &buf)); // Too small a caller buffer is NoSpace, not a truncation. var tiny: [4]u8 = undefined; @@ -947,9 +947,9 @@ test "post names: a 255-byte entry stages and iterates (NAME_MAX)" { // A 255-byte name can never be a socket (108-byte budget), but an // attacker can drop one in the registry; the raw listing must carry // it without overflowing the staged `len:u8` record. - const fat = "z" ** 255; + const fat: []const u8 = &@as([255]u8, @splat('z')); var fat_buf: [std.fs.max_path_bytes]u8 = undefined; - const fat_path = try std.fmt.bufPrintZ(&fat_buf, "{s}/{s}", .{ reg, fat }); + const fat_path = try std.fmt.bufPrintSentinel(&fat_buf, "{s}/{s}", .{ reg, fat }, 0); { var f = try Io.Dir.createFileAbsolute(io, fat_path, .{}); f.close(io); @@ -974,10 +974,10 @@ test "post long name: max_name_len posts, probes, dials and unposts" { // scratch directory of its own. const io = testing.io; var xdg_buf: [64]u8 = undefined; - const xdg = try std.fmt.bufPrintZ(&xdg_buf, "/tmp/.p9t{d}", .{linux.getpid()}); + const xdg = try std.fmt.bufPrintSentinel(&xdg_buf, "/tmp/.p9t{d}", .{linux.getpid()}, 0); _ = try Io.Dir.createDirPathStatus(.cwd(), io, xdg, .fromMode(0o700)); var env_buf: [96]u8 = undefined; - const value = try std.fmt.bufPrintZ(&env_buf, "XDG_RUNTIME_DIR={s}", .{xdg}); + const value = try std.fmt.bufPrintSentinel(&env_buf, "XDG_RUNTIME_DIR={s}", .{xdg}, 0); const env = [2]?[*:0]const u8{ @ptrCast(value.ptr), null }; const envp: Env = @ptrCast(&env); var dbuf: [std.fs.max_path_bytes]u8 = undefined; @@ -987,7 +987,7 @@ test "post long name: max_name_len posts, probes, dials and unposts" { _ = linux.rmdir(xdg.ptr); } var pbuf: [sun_path_len]u8 = undefined; - const name = "l" ** max_name_len; + const name: []const u8 = &@as([max_name_len]u8, @splat('l')); try testing.expect(legalName(name)); var p = try post(io, envp, name, 4, &pbuf); try testing.expect(probe(p.path) == .live); @@ -996,7 +996,7 @@ test "post long name: max_name_len posts, probes, dials and unposts" { unpost(io, p.path, p.inode); p.server.deinit(io); // One past the cap is not even a path. - const too_long = "l" ** (max_name_len + 1); + const too_long: []const u8 = &@as([max_name_len + 1]u8, @splat('l')); try testing.expect(!legalName(too_long)); try testing.expectError(error.IllegalName, registryPath(envp, too_long, &pbuf)); } @@ -1021,7 +1021,7 @@ test "post watch: queue overflow surfaces, a deleted registry is gone" { var name_buf: [std.fs.max_path_bytes]u8 = undefined; const spam = 20000; for (0..spam) |i| { - const p = try std.fmt.bufPrintZ(&name_buf, "{s}/q{d}", .{ reg, i }); + const p = try std.fmt.bufPrintSentinel(&name_buf, "{s}/q{d}", .{ reg, i }, 0); var f = try Io.Dir.createFileAbsolute(io, p, .{}); f.close(io); } @@ -1049,7 +1049,7 @@ test "post watch: queue overflow surfaces, a deleted registry is gone" { _ = try Io.Dir.createDirPathStatus(.cwd(), io, reg, .fromMode(0o750)); try w.add(reg); { - var f = try Io.Dir.createFileAbsolute(io, try std.fmt.bufPrintZ(&name_buf, "{s}/back", .{reg}), .{}); + var f = try Io.Dir.createFileAbsolute(io, try std.fmt.bufPrintSentinel(&name_buf, "{s}/back", .{reg}, 0), .{}); f.close(io); } const back = try w.next(); @@ -1091,7 +1091,7 @@ test "post dialPath: refused, missing, non-socket, loop and a CLOEXEC stream" { // A live socket: dialPath yields a blocking, close-on-exec stream // (the mounted PROGRAM must not inherit a dialed descriptor). - const sock_path = try std.fmt.bufPrintZ(&path_buf, "{s}/live.sock", .{root}); + const sock_path = try std.fmt.bufPrintSentinel(&path_buf, "{s}/live.sock", .{root}, 0); var server = try (try Io.net.UnixAddress.init(sock_path)).listen(io, .{}); { var st = try dialPath(io, sock_path); @@ -1104,13 +1104,13 @@ test "post dialPath: refused, missing, non-socket, loop and a CLOEXEC stream" { try testing.expectError(error.Stale, dialPath(io, sock_path)); // No entry at all. - try testing.expectError(error.NotPosted, dialPath(io, try std.fmt.bufPrintZ(&path_buf, "{s}/missing", .{root}))); + try testing.expectError(error.NotPosted, dialPath(io, try std.fmt.bufPrintSentinel(&path_buf, "{s}/missing", .{root}, 0))); // An entry that is not a socket answers the same ECONNREFUSED the // kernel gives a dead socket; the caller tells them apart by stat // before dialing (post.post does exactly that). - try testing.expectError(error.Stale, dialPath(io, try std.fmt.bufPrintZ(&path_buf, "{s}", .{root}))); - const file_path = try std.fmt.bufPrintZ(&path_buf, "{s}/plain", .{root}); + try testing.expectError(error.Stale, dialPath(io, try std.fmt.bufPrintSentinel(&path_buf, "{s}", .{root}, 0))); + const file_path = try std.fmt.bufPrintSentinel(&path_buf, "{s}/plain", .{root}, 0); { var f = try Io.Dir.createFileAbsolute(io, file_path, .{}); f.close(io); @@ -1118,7 +1118,7 @@ test "post dialPath: refused, missing, non-socket, loop and a CLOEXEC stream" { try testing.expectError(error.Stale, dialPath(io, file_path)); // A symlink loop is its own error, not a missing entry. - const loop_path = try std.fmt.bufPrintZ(&path_buf, "{s}/loop", .{root}); + const loop_path = try std.fmt.bufPrintSentinel(&path_buf, "{s}/loop", .{root}, 0); try Io.Dir.symLinkAbsolute(io, loop_path, loop_path, .{}); try testing.expectError(error.SymLinkLoop, dialPath(io, loop_path)); } @@ -1132,12 +1132,12 @@ test "post postedDir: a 1000-entry directory lists fully or refuses cleanly" { var real_buf: [std.fs.max_path_bytes]u8 = undefined; const rlen = try s.dir.dir.realPath(io, &real_buf); var dir_buf: [std.fs.max_path_bytes]u8 = undefined; - const dir = try std.fmt.bufPrintZ(&dir_buf, "{s}", .{real_buf[0..rlen]}); + const dir = try std.fmt.bufPrintSentinel(&dir_buf, "{s}", .{real_buf[0..rlen]}, 0); for (0..1000) |i| { var name_buf: [32]u8 = undefined; var path_buf: [std.fs.max_path_bytes]u8 = undefined; const name = try std.fmt.bufPrint(&name_buf, "e{d:0>4}", .{i}); - var f = try Io.Dir.createFileAbsolute(io, try std.fmt.bufPrintZ(&path_buf, "{s}/{s}", .{ dir, name }), .{}); + var f = try Io.Dir.createFileAbsolute(io, try std.fmt.bufPrintSentinel(&path_buf, "{s}/{s}", .{ dir, name }, 0), .{}); f.close(io); } // A staging buffer that cannot hold every record is an explicit -- cgit v1.3