authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-04-20 16:43:22 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-04-20 16:43:22 -07:00
log1578e667ed18b96b0335c6b550d0b0a052f70000
tree7dccbc6d7b095c8d347b3861b5d2f1ec1c1e0aa0
parent868f414152de3f73b7e6ba5b4b627b95252f2afc

add getuid


2 files changed, 9 insertions(+), 1 deletions(-)

mod.zig+8-1
......@@ -9,6 +9,7 @@ const syscall4 = sys.syscall4;
99const syscall5 = sys.syscall5;
1010const syscall6 = sys.syscall6;
1111const pid_t = sys.pid_t;
12const uid_t = sys.uid_t;
1213
1314fn _errno(rc: usize) enum(c_ushort) { ok, _ } {
1415 const signed: isize = @bitCast(rc);
......@@ -571,7 +572,13 @@ pub const ptrace = @compileError("TODO: ptrace");
571572// getuid
572573// uid_t getuid(void);
573574// asmlinkage long sys_getuid(void);
574pub const getuid = @compileError("TODO: getuid");
575pub fn getuid() errno.Error!uid_t {
576 const r = syscall0(.getuid);
577 return switch (_errno(r)) {
578 .ok => @intCast(r),
579 _ => |c| errno.errorFromInt(@intFromEnum(c)),
580 };
581}
575582
576583// syslog
577584// int syscall(SYS_syslog, int type, char *bufp, int len);
test.zig+1
......@@ -12,4 +12,5 @@ test {
1212 _ = &linux.getpid;
1313 _ = &linux.fork;
1414 _ = &linux.vfork;
15 _ = &linux.getuid;
1516}