From cb57a9976752642de2ab7d070c7f948c9b8d6bcf Mon Sep 17 00:00:00 2001 From: Gitea Date: Wed, 23 Dec 2020 23:08:54 -0600 Subject: [PATCH] Source PS1, add umask --- sh.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/sh.c b/sh.c index d207f61..bafcaa2 100755 --- a/sh.c +++ b/sh.c @@ -5,13 +5,13 @@ #include #include #include +#include #include #include #include #include #define ARG_SEP " " /* Argument separator for commands */ -#define PROMPT " $ " char** create_argv(char* command); int get_argc(char* command); @@ -20,11 +20,17 @@ char* prompt(); int cd(char* path); int _kill(int argc, char * argv[]); +mode_t _umask = 022; +char * prompt_str; +#define PROMPT prompt_str + int main() { char** argv; char* user_input; pid_t child_pid; int stat_loc; /* ??? (Needed for waitpid) */ + prompt_str = getenv("PS1"); + prompt_str = prompt_str == NULL ? "$ " : prompt_str; signal(SIGINT, SIG_IGN); @@ -47,6 +53,20 @@ int main() { strcmp(argv[0], "quit") == 0) { exit(0); } + else if(strcmp(argv[0], "umask") == 0) { + if(strcmp(argv[1], "-S") == 0) { + /* TODO: Print symbolic string. */ + } + else if(argv[1] != NULL) { + /* TODO: Implement symbolic support. */ + _umask = atoi(argv[1]); + umask(_umask); + } + else { + printf("%o\n", _umask); + } + continue; + } child_pid = fork(); if(child_pid < 0) {