Commit 56c61045 authored by abenoit's avatar abenoit
Browse files

finished replacing perror with strerror

parent 163af73e
......@@ -51,12 +51,14 @@ enum e_retcode
{
_EXIT_CODE_ = 2,
CLEAN_EXIT,
CHILD_EXIT,
ARG_ERR,
CHILD_EXIT,
CHILD_ERROR,
_ERRNO_MSG_,
MALLOC_ERR,
WRITE_ERR,
GNL_ERR,
INVALID_CD_PATH,
_EXEC_ERROR_,
AMBIG_REDIR,
HOME_NOT_SET,
......
......@@ -45,9 +45,6 @@ a la fin avec rgrep:
erreurs de write et de ft_put* a terminer
gestion d'erreurs des fonctions autorisees une a une
prompt printing "minishell"
builtins: set stat_loc?
......
#include "builtins.h"
#include <stdio.h> // perror
int ft_cd(char **args, t_xe *xe)
{
int ret;
......@@ -27,11 +25,10 @@ int ft_cd(char **args, t_xe *xe)
oldpwd = getcwd(NULL, 0); // error
if (chdir(path) == ERROR)
{
perror("cd"); // -> strerror
free(path);
free(oldpwd);
xe->stat_loc = 1;
return (SUCCESS); //notify failure anyway ?
return (INVALID_CD_PATH); //notify failure anyway ?
}
free(path);
env_replace_var("OLDPWD", oldpwd, xe);
......
#include "execution.h"
#include "builtins.h"
#include <stdio.h> // perror
static int launch_exit(char **args, t_xe *xe)
{
(void)args;
......@@ -60,8 +58,9 @@ static int exec_cmd(char *cmd, char **args, t_xe *xe)
{
xe->child = 1;
if (execve(cmd, args, xe->env) == ERROR)
perror("External function error:"); // -> strerror
return (CHILD_EXIT);
return (CHILD_ERROR);
else
return (CHILD_EXIT);
}
else
{
......
......@@ -50,10 +50,11 @@ static int err_output(int err_code)
const char *err_msg[] = {
"Memory allocation failure",
"Cannot write on standard output",
"Cannot read standard input (GNL error)"};
"Cannot read standard input (GNL error)",
"cd"};
ft_putstr_fd("error: ", STDERR_FILENO);
ft_putstr_fd(err_msg[err_code - _ERRNO_MSG_], STDERR_FILENO);
ft_putstr_fd(err_msg[err_code - _ERRNO_MSG_ -1], STDERR_FILENO);
ft_putstr_fd(": ", STDERR_FILENO); // besoin de faire comme perror?
ft_putendl_fd(strerror(errno), STDERR_FILENO); // strerror error?
return (SUCCESS);
......@@ -66,10 +67,17 @@ int clean_and_exit(int ret, t_xe *xe)
if (ft_putstr_fd("Minishell takes no argument", STDERR_FILENO) != WRITE_SUCCESS)
ft_error(WRITE_ERR, xe); // possible?
}
if (ret == CHILD_EXIT)
ret = (xe->stat_loc);
else
if (ret < CHILD_EXIT)
ret = EXIT_SUCCESS;
else
{
if (ret == CHILD_ERROR)
{
ft_putstr_fd("External function error:", STDERR_FILENO); // -> strerror
ft_putendl_fd(strerror(errno), STDERR_FILENO); // strerror error?
}
ret = (xe->stat_loc);
}
free_str_array(xe->exported); // besoin de free?
free_str_array(xe->env); // besoin de free?
free(xe);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment