os: passwd also gets username

This commit is contained in:
Mitchell Hashimoto
2023-12-13 15:35:21 -08:00
parent cc6270f549
commit 2732ca9c5c

View File

@ -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;
}