commit bc6041a4fbc18f4cc66670109732941c948be1db
parent 4e72da523d192c219cc7086f6d260b1b37211f4c
Author: Umar Getagazov <umar@handlerug.me>
Date: Fri, 9 Jul 2021 22:43:54 +0700
unix: add umask wrapper for Linux
Signed-off-by: Umar Getagazov <umar@handlerug.me>
Diffstat:
4 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib
@@ -770,7 +770,8 @@ unicode() {
unix() {
# XXX: getuid and setuid are probably platform-specific too
gen_srcs unix \
- nice'$(PLATFORM)'.ha \
+ '$(PLATFORM)/nice.ha' \
+ '$(PLATFORM)/umask.ha' \
getuid.ha \
setuid.ha
gen_ssa unix errors
diff --git a/stdlib.mk b/stdlib.mk
@@ -1099,7 +1099,8 @@ $(HARECACHE)/unicode/unicode.ssa: $(stdlib_unicode_srcs) $(stdlib_rt)
# unix
stdlib_unix_srcs= \
- $(STDLIB)/unix/nice$(PLATFORM).ha \
+ $(STDLIB)/unix/$(PLATFORM)/nice.ha \
+ $(STDLIB)/unix/$(PLATFORM)/umask.ha \
$(STDLIB)/unix/getuid.ha \
$(STDLIB)/unix/setuid.ha
@@ -2290,7 +2291,8 @@ $(TESTCACHE)/unicode/unicode.ssa: $(testlib_unicode_srcs) $(testlib_rt)
# unix
testlib_unix_srcs= \
- $(STDLIB)/unix/nice$(PLATFORM).ha \
+ $(STDLIB)/unix/$(PLATFORM)/nice.ha \
+ $(STDLIB)/unix/$(PLATFORM)/umask.ha \
$(STDLIB)/unix/getuid.ha \
$(STDLIB)/unix/setuid.ha
diff --git a/unix/nice+linux.ha b/unix/+linux/nice.ha
diff --git a/unix/+linux/umask.ha b/unix/+linux/umask.ha
@@ -0,0 +1,13 @@
+use errors;
+use fs;
+use rt;
+
+// Sets the file mode creation mask for the current process and return the
+// previous value of the mask. Only the file permission bits are used.
+export fn umask(mode: fs::mode) (fs::mode | errors::error) = {
+ mode &= 0o777;
+ return match (rt::umask(mode)) {
+ mode: rt::mode_t => mode: fs::mode,
+ err: rt::errno => errors::errno(err),
+ };
+};