std.posix: add getuid()/geteuid()

This commit is contained in:
blurrycat 2025-03-27 08:58:27 +01:00 committed by GitHub
parent dc66f4384f
commit fb188c3d18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 0 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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;