aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/std/os.zig3
-rw-r--r--lib/std/thread.zig2
-rw-r--r--lib/std/zig/system.zig26
3 files changed, 29 insertions, 2 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig
index 49e88bf9c7..24d78bec9a 100644
--- a/lib/std/os.zig
+++ b/lib/std/os.zig
@@ -2764,6 +2764,7 @@ pub const SysCtlError = error{
PermissionDenied,
SystemResources,
NameTooLong,
+ UnknownName,
} || UnexpectedError;
pub fn sysctl(
@@ -2779,6 +2780,7 @@ pub fn sysctl(
EFAULT => unreachable,
EPERM => return error.PermissionDenied,
ENOMEM => return error.SystemResources,
+ ENOENT => return error.UnknownName,
else => |err| return unexpectedErrno(err),
}
}
@@ -2795,6 +2797,7 @@ pub fn sysctlbynameC(
EFAULT => unreachable,
EPERM => return error.PermissionDenied,
ENOMEM => return error.SystemResources,
+ ENOENT => return error.UnknownName,
else => |err| return unexpectedErrno(err),
}
}
diff --git a/lib/std/thread.zig b/lib/std/thread.zig
index 55db9d1733..de9d580af7 100644
--- a/lib/std/thread.zig
+++ b/lib/std/thread.zig
@@ -382,7 +382,7 @@ pub const Thread = struct {
var count_len: usize = @sizeOf(c_int);
const name = if (comptime std.Target.current.isDarwin()) "hw.logicalcpu" else "hw.ncpu";
os.sysctlbynameC(name, &count, &count_len, null, 0) catch |err| switch (err) {
- error.NameTooLong => unreachable,
+ error.NameTooLong, error.UnknownName => unreachable,
else => |e| return e,
};
return @intCast(usize, count);
diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig
index aa8def32a9..7e23410fa8 100644
--- a/lib/std/zig/system.zig
+++ b/lib/std/zig/system.zig
@@ -224,7 +224,31 @@ pub const NativeTargetInfo = struct {
// TODO Detect native operating system version.
},
.macosx => {
- // TODO Detect native operating system version.
+ var product_version: [32]u8 = undefined;
+ var size: usize = product_version.len;
+
+ // The osproductversion sysctl was introduced first with
+ // High Sierra, thankfully that's also the baseline that Zig
+ // supports
+ std.os.sysctlbynameC(
+ "kern.osproductversion",
+ &product_version[0],
+ &size,
+ null,
+ 0,
+ ) catch |err| switch (err) {
+ error.UnknownName => unreachable,
+ else => unreachable,
+ };
+
+ if (std.builtin.Version.parse(product_version[0..size])) |ver| {
+ os.version_range.semver.min = ver;
+ os.version_range.semver.max = ver;
+ } else |err| switch (err) {
+ error.Overflow => {},
+ error.InvalidCharacter => {},
+ error.InvalidVersion => {},
+ }
},
.freebsd => {
// TODO Detect native operating system version.