diff --git a/include/builtins.h b/include/builtins.h index 97fcc15..ca56714 100644 --- a/include/builtins.h +++ b/include/builtins.h @@ -6,7 +6,7 @@ /* By: sede-san 2) + { + ft_eputendl("minishell: cd: too many arguments"); + return (2); + } + else if (cmd.argc == 1) + path = getenv("HOME"); + else + path = cmd.argv[1]; + if (chdir(path) == -1) + return (handle_error(cmd, msh, path)); + return (EXIT_SUCCESS); +} + +static u_int8_t handle_error( + t_command cmd, + t_minishell *msh, + char *path +){ + u_int8_t exit_code; + + if (access(path, F_OK) != -1) + // No such file or directory + exit_code = 1; + else if (access(path, X_OK) == -1) + // Permission denied + exit_code = 2; + perror(cmd.argv[0]); + return (exit_code); +}