From 1578e667ed18b96b0335c6b550d0b0a052f70000 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 20 Apr 2025 16:43:22 -0700 Subject: [PATCH] add getuid --- mod.zig | 9 ++++++++- test.zig | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mod.zig b/mod.zig index adf227638c0a0a3688ac5faeccbcf3e96459ea16..ea1d803dd44557009d10ae9a034b470c72bac4e6 100644 --- a/mod.zig +++ b/mod.zig @@ -9,6 +9,7 @@ const syscall4 = sys.syscall4; const syscall5 = sys.syscall5; const syscall6 = sys.syscall6; const pid_t = sys.pid_t; +const uid_t = sys.uid_t; fn _errno(rc: usize) enum(c_ushort) { ok, _ } { const signed: isize = @bitCast(rc); @@ -571,7 +572,13 @@ pub const ptrace = @compileError("TODO: ptrace"); // getuid // uid_t getuid(void); // asmlinkage long sys_getuid(void); -pub const getuid = @compileError("TODO: getuid"); +pub fn getuid() errno.Error!uid_t { + const r = syscall0(.getuid); + return switch (_errno(r)) { + .ok => @intCast(r), + _ => |c| errno.errorFromInt(@intFromEnum(c)), + }; +} // syslog // int syscall(SYS_syslog, int type, char *bufp, int len); diff --git a/test.zig b/test.zig index 9c78239ffb47f51b2e41fe63fa5fb337489c380d..7a81210a90b34847d7494ac4fdb0ddb6caa82dfe 100644 --- a/test.zig +++ b/test.zig @@ -12,4 +12,5 @@ test { _ = &linux.getpid; _ = &linux.fork; _ = &linux.vfork; + _ = &linux.getuid; } -- 2.54.0