diff --git a/result.txt b/result.txt index e69de29..f70ed64 100755 --- a/result.txt +++ b/result.txt @@ -0,0 +1,10 @@ +total 52 +drwxr-xr-x 4 root root 120 Mar 16 22:47 . +dr-xr-x---. 14 root root 4096 Mar 16 15:20 .. +drwxr-xr-x 8 root root 201 Mar 16 22:04 .git +-rw-r--r-- 1 root root 46 Mar 10 17:40 README.md +-rwx------ 1 root root 0 Mar 16 22:47 result.txt +drwxr-xr-x 2 root root 64 Mar 16 11:27 .vscode +-rwxr-xr-x 1 root root 23728 Mar 16 22:46 yeeshell +-rw-r--r-- 1 root root 13535 Mar 16 22:46 yeeshell.c +-rw-r--r-- 1 root root 3914 Mar 16 22:44 yeeshell.h diff --git a/yeeshell b/yeeshell index f9eda9d..05f3d9a 100755 Binary files a/yeeshell and b/yeeshell differ diff --git a/yeeshell.c b/yeeshell.c index 04f3c45..712e915 100644 --- a/yeeshell.c +++ b/yeeshell.c @@ -156,7 +156,7 @@ int check_redirect(char **args, char *redirect_filename, char **redirect_args) i++; } - if (redirect_flag == 1) /* redirect output */ + if ((redirect_flag == 1) || (redirect_flag == 2)) { strcpy(redirect_filename, args[i + 1]); for (j = 0; j < i; j++) @@ -164,15 +164,7 @@ int check_redirect(char **args, char *redirect_filename, char **redirect_args) redirect_args[j] = args[j]; } } - else if (redirect_flag == 2) /* redirect input */ - { - redirect_filename = args[0]; - i++; - while (args[i] != NULL) - { - redirect_args[j++] = args[i++]; - } - } + return redirect_flag; } @@ -181,16 +173,15 @@ int execute(char *cmdline, char **args) int bg = 0, i = 0, redirect_flag = 0, fd = 1; pid_t pid; char *redirect_filename = NULL; - redirect_filename = (char *)calloc(32, sizeof(char)); + redirect_filename = (char *)calloc(REDIRECT_FILENAME_MAX_SIZE, sizeof(char)); char *redirect_args[ARGS_MAX_QUANTITY]; + memset(redirect_args, NULL, sizeof(redirect_args)); sigset_t mask_all, mask_prev; sigprocmask(SIG_BLOCK, NULL, &mask_all); sigaddset(&mask_all, SIGCHLD); bg = parseline(cmdline, args); redirect_flag = check_redirect(args, redirect_filename, redirect_args); - printf("%s %s %s %s", redirect_args[0], redirect_args[1], redirect_args[2], redirect_filename); - if (args[0] == NULL) { return 1;