From 5c4dbbcef2ee11a05ab448ad307f6993285c90ae Mon Sep 17 00:00:00 2001 From: utox39 Date: Mon, 17 Mar 2025 01:09:46 +0100 Subject: [PATCH] feat(linux): add os info --- src/linux/linux.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/linux/linux.zig b/src/linux/linux.zig index 77752f5..418a0dc 100644 --- a/src/linux/linux.zig +++ b/src/linux/linux.zig @@ -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"); +}