diff --git a/src/boitoutil/essential_shell.c b/src/boitoutil/essential_shell.c index cc11047..45bee3b 100644 --- a/src/boitoutil/essential_shell.c +++ b/src/boitoutil/essential_shell.c @@ -17,6 +17,7 @@ #include pid_t pid; +int exit_code; /** * native_command(): vérifie si la commande entrée par l’utilisateur @@ -34,7 +35,7 @@ int native_command(char *command[]) { int ret = 1; /* 0 si commande non native */ if (!strcmp(command[0], "cd")) - change_dir(command[1]); + change_dir(command); if (!strcmp(command[0], "ouï-dire") || !strcmp(command[0], "oui-dire") || !strcmp(command[0], "echo")) { @@ -59,17 +60,26 @@ int native_command(char *command[]) * change_dir(): fonction pour implémenter la commande cd * @dir: le répertoire à ouvrir */ -void change_dir(char *dir) +void change_dir(char *command[]) { + char *dir = command[1]; if (chdir(dir) < 0) { int code = errno; - char txt_error[MAX_LENGTH] = "cd: "; + char *txt_error = calloc(MAX_LENGTH, sizeof(char)); + strcat(txt_error, command[0]); + strcat(txt_error, ": "); strcat(txt_error, dir); error(code, NON_FATAL_ERROR, txt_error); + free(txt_error); } } +//void thus_exit(char *command[]) +//{ +// exit_code = 0; +//} + void ctrl_c_handler() { //kill(pid, SIGTERM); diff --git a/src/boitoutil/essential_shell.h b/src/boitoutil/essential_shell.h index 48c99fc..82ce8e4 100644 --- a/src/boitoutil/essential_shell.h +++ b/src/boitoutil/essential_shell.h @@ -20,9 +20,11 @@ #define ERR_FORK 201 /* erreur lors du fork */ extern pid_t pid; +extern int exit_code; int native_command(char *command[]); -void change_dir(char *dir); +void change_dir(char *command[]); +//void thus_exit(char *command[]) void ctrl_c_handler(); void error(int code, int type, char *message);