aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorblurrycat <123909576+blurrycat@users.noreply.github.com>2025-03-27 08:58:27 +0100
committerGitHub <noreply@github.com>2025-03-27 07:58:27 +0000
commitfb188c3d18a744cb98fc361aeeb8e8796066868b (patch)
tree171dd8df55851a6ae36eb81416718e15ec972bdb /lib/std
parentdc66f4384f5ab4210f57f3fd37fd96cdd2823782 (diff)
downloadzig-fb188c3d18a744cb98fc361aeeb8e8796066868b.tar.gz
zig-fb188c3d18a744cb98fc361aeeb8e8796066868b.zip
std.posix: add getuid()/geteuid()
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/c.zig2
-rw-r--r--lib/std/posix.zig8
-rw-r--r--lib/std/posix/test.zig6
3 files changed, 16 insertions, 0 deletions
diff --git a/lib/std/c.zig b/lib/std/c.zig
index 2a68a68c4d..fc5497a5be 100644
--- a/lib/std/c.zig
+++ b/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;
diff --git a/lib/std/posix.zig b/lib/std/posix.zig
index 211d25a35a..8a5e974625 100644
--- a/lib/std/posix.zig
+++ b/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) {
diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig
index 9678bfb261..0efe76e55d 100644
--- a/lib/std/posix/test.zig
+++ b/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;