feat(linux): add os info

This commit is contained in:
utox39
2025-03-17 01:09:46 +01:00
parent d0d9881561
commit 5c4dbbcef2

View File

@@ -208,3 +208,27 @@ pub fn getKernelInfo(allocator: std.mem.Allocator) !KernelInfo {
.kernel_release = try allocator.dupe(u8, &uts.release), .kernel_release = try allocator.dupe(u8, &uts.release),
}; };
} }
pub fn getOsInfo(allocator: std.mem.Allocator) ![]u8 {
const os_release_path = "/etc/os-release";
const file = try std.fs.cwd().openFile(os_release_path, .{});
defer file.close();
const os_release_data = try file.readToEndAlloc(allocator, std.math.maxInt(usize));
defer allocator.free(os_release_data);
var pretty_name: ?[]const u8 = null;
var lines = std.mem.split(u8, os_release_data, "\n");
while (lines.next()) |line| {
if (std.mem.startsWith(u8, line, "PRETTY_NAME")) {
var parts = std.mem.split(u8, line, "=");
_ = parts.next(); // discard the key
if (parts.next()) |value| {
pretty_name = std.mem.trim(u8, value, "\"");
break;
}
}
}
return try allocator.dupe(u8, pretty_name orelse "Unknown");
}