diff --git a/sh.c b/sh.c index d56a652..68e1cba 100755 --- a/sh.c +++ b/sh.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include #include #include @@ -6,19 +8,6 @@ #include #include #include - -/* - Gods damn it, of course we have to have special shit - just for the fucking GNU Project. Fuckers can't let - anything be done to standard unless they fucking want - to or you beg them to let you, can they? - - -Kat -*/ -#ifdef __GLIBC__ -#define __USE_POSIX -#define __USE_POSIX2 -#endif #include #define ARG_SEP " " /* Argument separator for commands */ @@ -30,26 +19,26 @@ char* prompt(); int cd(char* path); int main() { - char** argv; /* The command with arguments */ + char** argv; char* user_input; pid_t child_pid; int stat_loc; /* ??? (Needed for waitpid) */ - signal(SIGINT, SIG_IGN); /* Tell vsh to ignore SIGINT (^C) */ + signal(SIGINT, SIG_IGN); while(1) { user_input = prompt(); argv = create_argv(user_input); if(strcmp(argv[0], "cd") == 0) { - if(cd(&user_input[3]) < 0) { - perror(argv[1]); + if(cd(argv[1]) < 0) { + perror(argv[1]); } /* causes the fork to get skipped */ continue; } else if(strcmp(argv[0], "exit") == 0 || - strcmp(argv[0], "quit") == 0) { + strcmp(argv[0], "quit") == 0) { exit(0); } @@ -57,25 +46,25 @@ int main() { if(child_pid < 0) { /* Could not start child process. Check why and error out. */ if(errno == EAGAIN) { - perror("Could not execute command: insufficient resources"); - exit(1); + perror("Could not execute command: insufficient resources"); + exit(1); } else if(errno == ENOMEM) { - /* Is this out of RAM or out of storage? */ - perror("Could not execute command: insufficient storage space"); - exit(1); + /* Is this out of RAM or out of storage? */ + perror("Could not execute command: insufficient storage space"); + exit(1); } else { - perror("Could not execute command: unknown failure"); - exit(1); + perror("Could not execute command: unknown failure"); + exit(1); } } else if(child_pid == 0) { /* We are the child, so allow ^C */ signal(SIGINT, SIG_DFL); if(execvp(argv[0], argv) < 0) { - perror(argv[0]); - exit(1); + perror(argv[0]); + exit(1); } } else {