Commit 7e63f7ad03
lib/std/os/linux/test.zig
@@ -9,6 +9,7 @@ const linux = std.os.linux;
const mem = std.mem;
const elf = std.elf;
const expect = std.testing.expect;
+const expectEqual = std.testing.expectEqual;
const fs = std.fs;
test "fallocate" {
@@ -99,3 +100,11 @@ test "statx" {
expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
}
+
+test "user and group ids" {
+ if (builtin.link_libc) return error.SkipZigTest;
+ expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());
+ expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());
+ expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());
+ expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());
+}
lib/std/os/linux.zig
@@ -745,33 +745,33 @@ pub fn setregid(rgid: gid_t, egid: gid_t) usize {
pub fn getuid() uid_t {
if (@hasField(SYS, "getuid32")) {
- return @as(uid_t, syscall0(.getuid32));
+ return @intCast(uid_t, syscall0(.getuid32));
} else {
- return @as(uid_t, syscall0(.getuid));
+ return @intCast(uid_t, syscall0(.getuid));
}
}
pub fn getgid() gid_t {
if (@hasField(SYS, "getgid32")) {
- return @as(gid_t, syscall0(.getgid32));
+ return @intCast(gid_t, syscall0(.getgid32));
} else {
- return @as(gid_t, syscall0(.getgid));
+ return @intCast(gid_t, syscall0(.getgid));
}
}
pub fn geteuid() uid_t {
if (@hasField(SYS, "geteuid32")) {
- return @as(uid_t, syscall0(.geteuid32));
+ return @intCast(uid_t, syscall0(.geteuid32));
} else {
- return @as(uid_t, syscall0(.geteuid));
+ return @intCast(uid_t, syscall0(.geteuid));
}
}
pub fn getegid() gid_t {
if (@hasField(SYS, "getegid32")) {
- return @as(gid_t, syscall0(.getegid32));
+ return @intCast(gid_t, syscall0(.getegid32));
} else {
- return @as(gid_t, syscall0(.getegid));
+ return @intCast(gid_t, syscall0(.getegid));
}
}