From 88e8e9fb911a93bfea0f57b28bdd3085ad370679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 6 Apr 2025 08:04:18 +0200 Subject: [PATCH] std: Remove some FreeBSD version checks and resulting dead code. We now require FreeBSD 13.4+. --- lib/std/os.zig | 61 +++++++++-------------------------------------- lib/std/posix.zig | 2 +- 2 files changed, 12 insertions(+), 51 deletions(-) diff --git a/lib/std/os.zig b/lib/std/os.zig index 3e9ec49e6e..f71180b5ee 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -158,57 +158,18 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix. return target; }, .freebsd => { - if (builtin.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0, .patch = 0 }) orelse false) { - var kfile: std.c.kinfo_file = undefined; - kfile.structsize = std.c.KINFO_FILE_SIZE; - switch (posix.errno(std.c.fcntl(fd, std.c.F.KINFO, @intFromPtr(&kfile)))) { - .SUCCESS => {}, - .BADF => return error.FileNotFound, - else => |err| return posix.unexpectedErrno(err), - } - const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse max_path_bytes; - if (len == 0) return error.NameTooLong; - const result = out_buffer[0..len]; - @memcpy(result, kfile.path[0..len]); - return result; - } else { - // This fallback implementation reimplements libutil's `kinfo_getfile()`. - // The motivation is to avoid linking -lutil when building zig or general - // user executables. - var mib = [4]c_int{ posix.CTL.KERN, posix.KERN.PROC, posix.KERN.PROC_FILEDESC, std.c.getpid() }; - var len: usize = undefined; - posix.sysctl(&mib, null, &len, null, 0) catch |err| switch (err) { - error.PermissionDenied => unreachable, - error.SystemResources => return error.SystemResources, - error.NameTooLong => unreachable, - error.UnknownName => unreachable, - else => return error.Unexpected, - }; - len = len * 4 / 3; - const buf = std.heap.c_allocator.alloc(u8, len) catch return error.SystemResources; - defer std.heap.c_allocator.free(buf); - len = buf.len; - posix.sysctl(&mib, &buf[0], &len, null, 0) catch |err| switch (err) { - error.PermissionDenied => unreachable, - error.SystemResources => return error.SystemResources, - error.NameTooLong => unreachable, - error.UnknownName => unreachable, - else => return error.Unexpected, - }; - var i: usize = 0; - while (i < len) { - const kf: *align(1) std.c.kinfo_file = @ptrCast(&buf[i]); - if (kf.fd == fd) { - len = mem.indexOfScalar(u8, &kf.path, 0) orelse max_path_bytes; - if (len == 0) return error.NameTooLong; - const result = out_buffer[0..len]; - @memcpy(result, kf.path[0..len]); - return result; - } - i += @intCast(kf.structsize); - } - return error.FileNotFound; + var kfile: std.c.kinfo_file = undefined; + kfile.structsize = std.c.KINFO_FILE_SIZE; + switch (posix.errno(std.c.fcntl(fd, std.c.F.KINFO, @intFromPtr(&kfile)))) { + .SUCCESS => {}, + .BADF => return error.FileNotFound, + else => |err| return posix.unexpectedErrno(err), } + const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse max_path_bytes; + if (len == 0) return error.NameTooLong; + const result = out_buffer[0..len]; + @memcpy(result, kfile.path[0..len]); + return result; }, .dragonfly => { @memset(out_buffer[0..max_path_bytes], 0); diff --git a/lib/std/posix.zig b/lib/std/posix.zig index 2399fbc9c8..4e3fa29f6c 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -6591,7 +6591,7 @@ pub const CopyFileRangeError = error{ /// /// Maximum offsets on Linux and FreeBSD are `maxInt(i64)`. pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len: usize, flags: u32) CopyFileRangeError!usize { - if ((comptime builtin.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0, .patch = 0 }) orelse false) or + if (builtin.os.tag == .freebsd or (comptime builtin.os.tag == .linux and std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }))) { var off_in_copy: i64 = @bitCast(off_in);