std.process: further totalSystemMemory portage

This commit is contained in:
David CARLIER
2023-04-22 13:47:01 +01:00
committed by Veikka Tuominen
parent c66151a226
commit 5c70d7bc72

View File

@@ -1163,12 +1163,17 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
.linux => {
return totalSystemMemoryLinux() catch return error.UnknownTotalSystemMemory;
},
.freebsd => {
.freebsd, .netbsd, .openbsd, .dragonfly, .macos => {
var physmem: c_ulong = undefined;
var len: usize = @sizeOf(c_ulong);
os.sysctlbynameZ("hw.physmem", &physmem, &len, null, 0) catch |err| switch (err) {
const name = switch (builtin.os.tag) {
.macos => "hw.memsize",
.netbsd => "hw.physmem64",
else => "hw.physmem",
};
os.sysctlbynameZ(name, &physmem, &len, null, 0) catch |err| switch (err) {
error.NameTooLong, error.UnknownName => unreachable,
else => |e| return e,
else => return error.UnknownTotalSystemMemory,
};
return @intCast(usize, physmem);
},