link: fix support for archs without fstat

Change-Id: I5db6a541dd9e3827d055dc7e9ea695c8f7d1324c
This commit is contained in:
Bingwu Zhang 2025-11-22 18:05:38 +08:00
parent 8facfbbcad
commit a1fe4f299d
No known key found for this signature in database
GPG key ID: B918086ED8045B91

View file

@ -53,6 +53,17 @@ pub fn init(file: std.Io.File, gpa: std.mem.Allocator) !MappedFile {
else => std.heap.page_size_max,
},
};
} else if (is_linux) {
var statx: linux.Statx = undefined;
switch (linux.errno(linux.statx(mf.file.handle, "", linux.AT.EMPTY_PATH, linux.STATX_TYPE | linux.STATX_SIZE, &statx))) {
.SUCCESS => {},
.INVAL, .LOOP => unreachable,
.NOMEM => return error.SystemResources,
.ACCES => return error.AccessDenied,
else => |err| return std.posix.unexpectedErrno(err),
}
if (statx.mode != linux.S.IFREG) return error.PathAlreadyExists;
break :stat .{ statx.size, @max(std.heap.pageSize(), statx.blksize) };
}
const stat = try std.posix.fstat(mf.file.handle);
if (!std.posix.S.ISREG(stat.mode)) return error.PathAlreadyExists;