commit b80be88
Michael Forney
·
2026-04-19 21:14:23 +0000 UTC
parent 5cdf453
rc: Implement umask missing from 9front's version
2 files changed,
+101,
-1
1@@ -0,0 +1,100 @@
2+From 5f3ce26ce56378ff2bfd7662627a02c1be8da6ce Mon Sep 17 00:00:00 2001
3+From: Michael Forney <mforney@mforney.org>
4+Date: Sun, 19 Apr 2026 14:11:15 -0700
5+Subject: [PATCH] implement umask builtin on unix
6+
7+---
8+ exec.h | 2 +-
9+ unix.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
10+ 2 files changed, 47 insertions(+), 1 deletion(-)
11+
12+diff --git a/exec.h b/exec.h
13+index 69b1004..ee8edab 100644
14+--- a/exec.h
15++++ b/exec.h
16+@@ -77,7 +77,7 @@ extern void (*builtinfunc(char *name))(void);
17+ void execcd(void), execwhatis(void), execeval(void), execexec(void);
18+ int execforkexec(void);
19+ void execexit(void), execshift(void);
20+-void execwait(void), execumask(void), execdot(void), execflag(void);
21++void execwait(void), execdot(void), execflag(void);
22+ void execfunc(var*), execcmds(io*, char*, var*, redir*);
23+ void startfunc(var*, word*, var*, redir*);
24+
25+diff --git a/unix.c b/unix.c
26+index 05d883c..cbb2054 100644
27+--- a/unix.c
28++++ b/unix.c
29+@@ -12,9 +12,12 @@
30+ #include <errno.h>
31+ #include <fcntl.h>
32+ #include <dirent.h>
33++#include <limits.h>
34++#include <sys/stat.h>
35+ #include <sys/wait.h>
36+
37+ static void execfinit(void);
38++static void execumask(void);
39+
40+ builtin Builtin[] = {
41+ "cd", execcd,
42+@@ -24,6 +27,7 @@ builtin Builtin[] = {
43+ "exit", execexit,
44+ "shift", execshift,
45+ "wait", execwait,
46++ "umask", execumask,
47+ ".", execdot,
48+ "flag", execflag,
49+ "finit", execfinit,
50+@@ -81,6 +85,48 @@ execfinit(void)
51+ start(rdfns, 2, runq->local, runq->redir);
52+ }
53+
54++static int
55++octal(char *s)
56++{
57++ int n = 0;
58++
59++ while(n<INT_MAX/8 && '0'<=*s && *s<='7')
60++ n = n*8+*s++-'0';
61++ return *s=='\0' ? n : -1;
62++}
63++
64++static void
65++execumask(void)
66++{
67++ int m;
68++ struct io *out;
69++ char *e;
70++
71++ switch(count(runq->argv->words)){
72++ case 2:
73++ m = octal(runq->argv->words->next->word);
74++ if(m>=0 && m<=07777) {
75++ umask(m);
76++ break;
77++ }
78++ /* fallthrough */
79++ default:
80++ pfmt(err, "Usage: umask [umask]\n");
81++ setstatus("umask usage");
82++ poplist();
83++ return;
84++ case 1:
85++ umask(m = umask(0));
86++ out = openiofd(mapfd(1));
87++ pfmt(out, "%o\n", m);
88++ flushio(out);
89++ free(closeiostr(out));
90++ break;
91++ }
92++ setstatus("");
93++ poplist();
94++}
95++
96+ static int
97+ cmpenv(const void *aa, const void *ab)
98+ {
99+--
100+2.49.0
101+
+1,
-1
1@@ -1 +1 @@
2-7c49b6bc9d r0
3+3e907e648d r1