Skip to content

Commit 6c582fb

Browse files
committed
link: fix support for archs without fstat
Change-Id: I5db6a541dd9e3827d055dc7e9ea695c8f7d1324c
1 parent 8facfbb commit 6c582fb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/link/MappedFile.zig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ pub fn init(file: std.Io.File, gpa: std.mem.Allocator) !MappedFile {
5454
},
5555
};
5656
}
57+
if (is_linux and !linux.have_fstat) {
58+
var statx: linux.Statx = undefined;
59+
switch (linux.errno(linux.statx(mf.file.handle, "", linux.AT.EMPTY_PATH, linux.STATX_TYPE | linux.STATX_SIZE, &statx))) {
60+
.SUCCESS => {},
61+
.INVAL, .LOOP => unreachable,
62+
.NOMEM => return error.SystemResources,
63+
.ACCES => return error.AccessDenied,
64+
else => |err| return std.posix.unexpectedErrno(err),
65+
}
66+
if (statx.mode != linux.S.IFREG) return error.PathAlreadyExists;
67+
break :stat .{ statx.size, @max(std.heap.pageSize(), statx.blksize) };
68+
}
5769
const stat = try std.posix.fstat(mf.file.handle);
5870
if (!std.posix.S.ISREG(stat.mode)) return error.PathAlreadyExists;
5971
break :stat .{ @bitCast(stat.size), @max(std.heap.pageSize(), stat.blksize) };

0 commit comments

Comments
 (0)