feat(linux): add os info
This commit is contained in:
@@ -208,3 +208,27 @@ pub fn getKernelInfo(allocator: std.mem.Allocator) !KernelInfo {
|
||||
.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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user