Source PS1, add umask

This commit is contained in:
Gitea 2020-12-23 23:08:54 -06:00
parent b0604ae476
commit cb57a99767
1 changed files with 21 additions and 1 deletions

22
sh.c
View File

@ -5,13 +5,13 @@
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <signal.h>
#include <libgen.h>
#include <errno.h>
#include <limits.h>
#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) {