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;...@@ -9,6 +9,7 @@ const syscall4 = sys.syscall4;
9const syscall5 = sys.syscall5;9const syscall5 = sys.syscall5;
10const syscall6 = sys.syscall6;10const syscall6 = sys.syscall6;
11const pid_t = sys.pid_t;11const pid_t = sys.pid_t;
12const uid_t = sys.uid_t;
1213
13fn _errno(rc: usize) enum(c_ushort) { ok, _ } {14fn _errno(rc: usize) enum(c_ushort) { ok, _ } {
14 const signed: isize = @bitCast(rc);15 const signed: isize = @bitCast(rc);
...@@ -571,7 +572,13 @@ pub const ptrace = @compileError("TODO: ptrace");...@@ -571,7 +572,13 @@ pub const ptrace = @compileError("TODO: ptrace");
571// getuid572// getuid
572// uid_t getuid(void);573// uid_t getuid(void);
573// asmlinkage long sys_getuid(void);574// 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
576// syslog583// syslog
577// int syscall(SYS_syslog, int type, char *bufp, int len);584// int syscall(SYS_syslog, int type, char *bufp, int len);
test.zig+1
...@@ -12,4 +12,5 @@ test {...@@ -12,4 +12,5 @@ test {
12 _ = &linux.getpid;12 _ = &linux.getpid;
13 _ = &linux.fork;13 _ = &linux.fork;
14 _ = &linux.vfork;14 _ = &linux.vfork;
15 _ = &linux.getuid;
15}16}