Commit fb188c3d18

blurrycat <123909576+blurrycat@users.noreply.github.com>
2025-03-27 08:58:27
std.posix: add getuid()/geteuid()
1 parent dc66f43
Changed files (3)
lib/std/posix/test.zig
@@ -509,6 +509,12 @@ test "getcwd" {
     _ = posix.getcwd(&buf) catch undefined;
 }
 
+test "getuid" {
+    if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
+    _ = posix.getuid();
+    _ = posix.geteuid();
+}
+
 test "sigaltstack" {
     if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
 
lib/std/c.zig
@@ -10547,6 +10547,8 @@ pub extern "c" fn setregid(rgid: gid_t, egid: gid_t) c_int;
 pub extern "c" fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) c_int;
 pub extern "c" fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) c_int;
 pub extern "c" fn setpgid(pid: pid_t, pgid: pid_t) c_int;
+pub extern "c" fn getuid() uid_t;
+pub extern "c" fn geteuid() uid_t;
 
 pub extern "c" fn malloc(usize) ?*anyopaque;
 pub extern "c" fn calloc(usize, usize) ?*anyopaque;
lib/std/posix.zig
@@ -3505,6 +3505,14 @@ pub fn setpgid(pid: pid_t, pgid: pid_t) SetPgidError!void {
     }
 }
 
+pub fn getuid() uid_t {
+    return system.getuid();
+}
+
+pub fn geteuid() uid_t {
+    return system.geteuid();
+}
+
 /// Test whether a file descriptor refers to a terminal.
 pub fn isatty(handle: fd_t) bool {
     if (native_os == .windows) {