From 4a05196764468ee9bb1aa6b1b105376b424cc948 Mon Sep 17 00:00:00 2001 From: utox39 Date: Mon, 10 Mar 2025 23:10:43 +0100 Subject: [PATCH] feat(macos): add os info --- src/macos/macos.zig | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/macos/macos.zig b/src/macos/macos.zig index c5f80eb..ac3521d 100644 --- a/src/macos/macos.zig +++ b/src/macos/macos.zig @@ -282,3 +282,25 @@ pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 { const term_progrm = try std.process.getEnvVarOwned(allocator, "TERM_PROGRAM"); return term_progrm; } + +pub fn getOsInfo(allocator: std.mem.Allocator) ![]u8 { + var size: usize = 0; + + // First call to sysctlbyname to get the size of the string + if (c_sysctl.sysctlbyname("kern.osproductversion", null, &size, null, 0) != 0) { + return error.FailedToGetCpuNameSize; + } + + const os_version: []u8 = try allocator.alloc(u8, size - 1); + defer allocator.free(os_version); + + // Second call to sysctlbyname to get the os version + if (c_sysctl.sysctlbyname("kern.osproductversion", os_version.ptr, &size, null, 0) != 0) { + allocator.free(os_version); + return error.FailedToGetOsVersion; + } + + const os_info = try std.fmt.allocPrint(allocator, "macOS {s}", .{os_version}); + + return os_info; +}