From b42dcfb108989d516acc4a8a983ecd2ffdde5559 Mon Sep 17 00:00:00 2001 From: Avery Terrel Date: Wed, 11 Mar 2026 09:45:39 +0000 Subject: [PATCH] sh.c: add umask builtin POSIX specifies -S, and Bash also has -p, but I haven't encountered anything that uses them so I didn't implement them. Signed-off-by: Avery Terrel --- toys/pending/sh.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/toys/pending/sh.c b/toys/pending/sh.c index 1f4ff3af..213f195b 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -62,6 +62,7 @@ USE_SH(NEWTOY(shift, ">1", TOYFLAG_NOFORK)) USE_SH(NEWTOY(source, "<1", TOYFLAG_NOFORK)) USE_SH(OLDTOY(., source, TOYFLAG_NOFORK)) USE_SH(NEWTOY(trap, "lp", TOYFLAG_NOFORK)) +USE_SH(NEWTOY(umask, ">1", TOYFLAG_NOFORK)) USE_SH(NEWTOY(unalias, "<1a", TOYFLAG_NOFORK)) USE_SH(NEWTOY(unset, "fvn[!fv]", TOYFLAG_NOFORK)) USE_SH(NEWTOY(wait, "n", TOYFLAG_NOFORK)) @@ -345,6 +346,16 @@ config TRAP The special signal EXIT gets called before the shell exits, RETURN when a function or source returns, and DEBUG is called before each command. +config UMASK +bool + default n + depends on SH + help + usage: umask [mask] + + Sets the file creation mode mask. + An empty mask causes the current mask to be printed. + config UNALIAS bool default n @@ -5161,6 +5172,15 @@ void source_main(void) TT.ff->arg.c = ii; } +void umask_main(void) +{ + if (toys.optc) { + toys.old_umask = string_to_mode(*toys.optargs, 0); + } else { + printf("%04o\n", umask(0)); + } +} + #define FOR_unalias #include "generated/flags.h" -- 2.39.5