diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-10 17:39:30 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-10 17:39:30 +0200 |
commit | c838a2e6529e4e7329c24c9f56399f378281967b (patch) | |
tree | b891cba106e63af698a044913f61c513ae0efc80 /Shell/main.cpp | |
parent | c1b025b5a6dfc30242064d1dfc95e79204c7b531 (diff) | |
download | serenity-c838a2e6529e4e7329c24c9f56399f378281967b.zip |
Shell: Add "umask" builtin for reading/writing the shell's umask.
Diffstat (limited to 'Shell/main.cpp')
-rw-r--r-- | Shell/main.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Shell/main.cpp b/Shell/main.cpp index b8d3dd0559..98009d8c58 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -121,6 +121,26 @@ static int sh_history(int, char**) return 0; } +static int sh_umask(int argc, char** argv) +{ + if (argc == 1) { + mode_t old_mask = umask(0); + printf("%#o\n", old_mask); + umask(old_mask); + return 0; + } + if (argc == 2) { + unsigned mask; + int matches = sscanf(argv[1], "%o", &mask); + if (matches == 1) { + umask(mask); + return 0; + } + } + printf("usage: umask <octal-mask>\n"); + return 0; +} + static bool handle_builtin(int argc, char** argv, int& retval) { if (argc == 0) @@ -145,6 +165,10 @@ static bool handle_builtin(int argc, char** argv, int& retval) retval = sh_history(argc, argv); return true; } + if (!strcmp(argv[0], "umask")) { + retval = sh_umask(argc, argv); + return true; + } return false; } |