commit 3a6d409e84e13fba8972da4c641e8b52b06822de
parent c4454dbbac80581b4dee4eb8b67b4bbb8bd49240
Author: Drew DeVault <sir@cmpwn.com>
Date: Mon, 5 Apr 2021 11:42:34 -0400
unix: add getuid, gid, euid, egid
Diffstat:
4 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha
@@ -559,3 +559,19 @@ export fn setresgid(gid: gid_t, egid: gid_t, sgid: gid_t) (void | errno) = {
wrap_return(syscall3(SYS_setresgid, gid: u64, egid: u64, sgid: u64))?;
return;
};
+
+export fn getresuid(uid: *uid_t, euid: *uid_t, suid: *uid_t) (void | errno) = {
+ wrap_return(syscall3(SYS_getresuid,
+ uid: uintptr: u64,
+ euid: uintptr: u64,
+ suid: uintptr: u64))?;
+ return;
+};
+
+export fn getresgid(gid: *gid_t, egid: *gid_t, sgid: *gid_t) (void | errno) = {
+ wrap_return(syscall3(SYS_getresgid,
+ gid: uintptr: u64,
+ egid: uintptr: u64,
+ sgid: uintptr: u64))?;
+ return;
+};
diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib
@@ -572,6 +572,7 @@ unicode() {
unix() {
gen_srcs unix \
+ getuid.ha \
setuid.ha
gen_ssa unix
}
diff --git a/stdlib.mk b/stdlib.mk
@@ -762,6 +762,7 @@ $(HARECACHE)/unicode/unicode.ssa: $(stdlib_unicode_srcs) $(stdlib_rt)
# unix
stdlib_unix_srcs= \
+ $(STDLIB)/unix/getuid.ha \
$(STDLIB)/unix/setuid.ha
$(HARECACHE)/unix/unix.ssa: $(stdlib_unix_srcs) $(stdlib_rt)
@@ -1568,6 +1569,7 @@ $(TESTCACHE)/unicode/unicode.ssa: $(testlib_unicode_srcs) $(testlib_rt)
# unix
testlib_unix_srcs= \
+ $(STDLIB)/unix/getuid.ha \
$(STDLIB)/unix/setuid.ha
$(TESTCACHE)/unix/unix.ssa: $(testlib_unix_srcs) $(testlib_rt)
diff --git a/unix/getuid.ha b/unix/getuid.ha
@@ -0,0 +1,29 @@
+use rt;
+
+// Returns the current process user ID.
+export fn getuid() uint = {
+ let uid = 0u, euid = 0u, suid = 0u;
+ rt::getresuid(&uid, &euid, &suid) as void;
+ return uid;
+};
+
+// Returns the current process effective user ID.
+export fn geteuid() uint = {
+ let uid = 0u, euid = 0u, suid = 0u;
+ rt::getresuid(&uid, &euid, &suid) as void;
+ return euid;
+};
+
+// Returns the current process group ID.
+export fn getgid() uint = {
+ let gid = 0u, egid = 0u, sgid = 0u;
+ rt::getresgid(&gid, &egid, &sgid) as void;
+ return gid;
+};
+
+// Returns the current process effective group ID.
+export fn getegid() uint = {
+ let gid = 0u, egid = 0u, sgid = 0u;
+ rt::getresgid(&gid, &egid, &sgid) as void;
+ return egid;
+};