mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
add macOS handling for totalSystemMemory (#24903)
* add macos handling for totalSystemMemory * fix return type cast for .freebsd in totalSystemMemory * add handling for the whole Darwin family in totalSystemMemory
This commit is contained in:
parent
b2578329af
commit
6f07cc95d0
1 changed files with 14 additions and 1 deletions
|
|
@ -1762,7 +1762,20 @@ pub fn totalSystemMemory() TotalSystemMemoryError!u64 {
|
||||||
error.NameTooLong, error.UnknownName => unreachable,
|
error.NameTooLong, error.UnknownName => unreachable,
|
||||||
else => return error.UnknownTotalSystemMemory,
|
else => return error.UnknownTotalSystemMemory,
|
||||||
};
|
};
|
||||||
return @as(usize, @intCast(physmem));
|
return @as(u64, @intCast(physmem));
|
||||||
|
},
|
||||||
|
// whole Darwin family
|
||||||
|
.driverkit, .ios, .macos, .tvos, .visionos, .watchos => {
|
||||||
|
// "hw.memsize" returns uint64_t
|
||||||
|
var physmem: u64 = undefined;
|
||||||
|
var len: usize = @sizeOf(u64);
|
||||||
|
posix.sysctlbynameZ("hw.memsize", &physmem, &len, null, 0) catch |err| switch (err) {
|
||||||
|
error.PermissionDenied => unreachable, // only when setting values,
|
||||||
|
error.SystemResources => unreachable, // memory already on the stack
|
||||||
|
error.UnknownName => unreachable, // constant, known good value
|
||||||
|
else => return error.UnknownTotalSystemMemory,
|
||||||
|
};
|
||||||
|
return physmem;
|
||||||
},
|
},
|
||||||
.openbsd => {
|
.openbsd => {
|
||||||
const mib: [2]c_int = [_]c_int{
|
const mib: [2]c_int = [_]c_int{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue