Commit 88e8e9fb91
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);
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);