Some minor tweaks
This commit is contained in:
parent
6731edbf57
commit
ae31e82b64
1 changed files with 16 additions and 27 deletions
21
sh.c
21
sh.c
|
@ -1,3 +1,5 @@
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -6,19 +8,6 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
/*
|
|
||||||
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 <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#define ARG_SEP " " /* Argument separator for commands */
|
#define ARG_SEP " " /* Argument separator for commands */
|
||||||
|
@ -30,19 +19,19 @@ char* prompt();
|
||||||
int cd(char* path);
|
int cd(char* path);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char** argv; /* The command with arguments */
|
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) */
|
||||||
|
|
||||||
signal(SIGINT, SIG_IGN); /* Tell vsh to ignore SIGINT (^C) */
|
signal(SIGINT, SIG_IGN);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
user_input = prompt();
|
user_input = prompt();
|
||||||
argv = create_argv(user_input);
|
argv = create_argv(user_input);
|
||||||
|
|
||||||
if(strcmp(argv[0], "cd") == 0) {
|
if(strcmp(argv[0], "cd") == 0) {
|
||||||
if(cd(&user_input[3]) < 0) {
|
if(cd(argv[1]) < 0) {
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
}
|
}
|
||||||
/* causes the fork to get skipped */
|
/* causes the fork to get skipped */
|
||||||
|
|
Loading…
Reference in a new issue