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) {