mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Shell: Add "umask" builtin for reading/writing the shell's umask.
This commit is contained in:
parent
c1b025b5a6
commit
c838a2e652
Notes:
sideshowbarker
2024-07-19 14:11:04 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/c838a2e6529
1 changed files with 24 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue