Source PS1, add umask

This commit is contained in:
Gitea 2020-12-23 23:08:54 -06:00
parent b0604ae476
commit cb57a99767

22
sh.c
View file

@ -5,13 +5,13 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/stat.h>
#include <signal.h> #include <signal.h>
#include <libgen.h> #include <libgen.h>
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#define ARG_SEP " " /* Argument separator for commands */ #define ARG_SEP " " /* Argument separator for commands */
#define PROMPT " $ "
char** create_argv(char* command); char** create_argv(char* command);
int get_argc(char* command); int get_argc(char* command);
@ -20,11 +20,17 @@ char* prompt();
int cd(char* path); int cd(char* path);
int _kill(int argc, char * argv[]); int _kill(int argc, char * argv[]);
mode_t _umask = 022;
char * prompt_str;
#define PROMPT prompt_str
int main() { int main() {
char** argv; char** argv;
char* user_input; char* user_input;
pid_t child_pid; pid_t child_pid;
int stat_loc; /* ??? (Needed for waitpid) */ int stat_loc; /* ??? (Needed for waitpid) */
prompt_str = getenv("PS1");
prompt_str = prompt_str == NULL ? "$ " : prompt_str;
signal(SIGINT, SIG_IGN); signal(SIGINT, SIG_IGN);
@ -47,6 +53,20 @@ int main() {
strcmp(argv[0], "quit") == 0) { strcmp(argv[0], "quit") == 0) {
exit(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(); child_pid = fork();
if(child_pid < 0) { if(child_pid < 0) {