diff --git a/vsh.c b/vsh.c index 00e7c88..f36abb7 100644 --- a/vsh.c +++ b/vsh.c @@ -17,12 +17,12 @@ int main(int argc, char** argv, char** envp){ running = 1; char pwd[DIR_STR_SIZ]; const long ARG_MAX = sysconf(_SC_ARG_MAX); - char cmdbuf[ARG_MAX]; + char* cmdbuf = malloc(sizeof(char) * ARG_MAX); //This holds all the args that a child could be passed. //ARG_MAX is the maximum length of an argument, so there //can never be more than ARG_MAX/2 arguments (assuming there //are ARG_MAX arguments of 1 char each separated by spaces) - char* child_argv[ARG_MAX / 2]; + char** child_argv = malloc(sizeof(char) * (ARG_MAX / 2)); last_argv = child_argv; char user_prompt = '$'; @@ -35,7 +35,7 @@ int main(int argc, char** argv, char** envp){ while(running){ - + //Get the current working directory. If an error occurs, then //set the pwd string to empty if(getcwd(pwd, DIR_STR_SIZ) != pwd){ @@ -55,8 +55,8 @@ int main(int argc, char** argv, char** envp){ //Get our argc and fill our argv int child_argc = get_args(args, child_argv); - //See if the command we've been given should be - //executed internally. If not, assume it's a + //See if the command we've been given should be + //executed internally. If not, assume it's a //program run_builtin_command(child_argc, child_argv); if(!builtin_cmd_found){ @@ -67,18 +67,19 @@ int main(int argc, char** argv, char** envp){ } wait(NULL); } - + //If the user ran a command built in to the shell //(like cd), and it had an error, print that error if(builtin_cmd_found && last_cmd_code){ print_error(); - } - + } + free_args(args); - + } puts("Exiting"); - + free(cmdbuf); + free(child_argv); deinit_builtin_commands(); return 0;