From 2732ca9c5cb3a621006287614b411c9b1a741dc9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 13 Dec 2023 15:35:21 -0800 Subject: [PATCH] os: passwd also gets username --- src/os/passwd.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/os/passwd.zig b/src/os/passwd.zig index 8aaf5ed42..f93d42f1b 100644 --- a/src/os/passwd.zig +++ b/src/os/passwd.zig @@ -26,6 +26,7 @@ const c = if (builtin.os.tag != .windows) @cImport({ pub const Entry = struct { shell: ?[]const u8 = null, home: ?[]const u8 = null, + name: ?[]const u8 = null, }; /// Get the passwd entry for the currently executing user. @@ -134,6 +135,13 @@ pub fn get(alloc: Allocator) !Entry { result.home = dir; } + if (pw.pw_name) |ptr| { + const source = std.mem.sliceTo(ptr, 0); + const name = try alloc.alloc(u8, source.len); + @memcpy(name, source); + result.name = name; + } + return result; }