Commit f8109c61 authored by abenoit's avatar abenoit
Browse files

merge

parents 34b1c107 cd238649
......@@ -60,6 +60,7 @@ enum e_retcode
WRITE_ERR,
GNL_ERR,
INVALID_CD_PATH,
INVALID_CD_NEW_PATH,
INVALID_PWD_PATH,
FD_ERROR,
_EXEC_ERROR_,
......@@ -68,6 +69,7 @@ enum e_retcode
NO_SUCH_FILE,
INVALID_EXP_ID,
INVALID_UNS_ID,
CD_ARG_ERR,
EXIT_ARG_ERR,
_PARSING_ERROR_,
SQUOTE_MISSING,
......
......@@ -14,27 +14,31 @@ int ft_cd(char **args, t_xe *xe)
path = get_var_value(xe->env, "HOME", 4);
}
else if (args[2] != NULL)
{
printf("trop d'arguments\n"); // temp
return (FAILURE); // temp
}
return (CD_ARG_ERR);
else
path = ft_strdup(args[1]);
if (path == NULL)
return (MALLOC_ERR); // err
oldpwd = getcwd(NULL, 0); // error
return (MALLOC_ERR);
oldpwd = get_var_value(xe->env, "PWD", 3);
if (oldpwd == NULL)
{
free(path);
return (MALLOC_ERR);
}
if (chdir(path) == ERROR)
{
free(path);
free(oldpwd);
xe->stat_loc = 1;
return (INVALID_CD_PATH); //notify failure anyway ?
return (INVALID_CD_PATH);
}
free(path);
env_replace_var("OLDPWD", oldpwd, xe);
env_replace_var("OLDPWD", oldpwd, xe);// erreur
free(oldpwd);
path = getcwd(NULL, 0);
env_replace_var("PWD", path, xe);
if (path == NULL)
return (INVALID_CD_NEW_PATH);
env_replace_var("PWD", path, xe);// erreur
free(path);
xe->stat_loc = 0;
return (SUCCESS);
......
......@@ -10,7 +10,7 @@ int ft_pwd(char **args, t_xe *xe)
if (buf == NULL)
{
xe->stat_loc = 1;
return (INVALID_PWD_PATH); // other code!
return (INVALID_PWD_PATH);
}
if (ft_putendl_fd(buf, STDOUT_FILENO) != WRITE_SUCCESS)
{
......
......@@ -30,6 +30,7 @@ int exec_error(int err_code, t_xe *xe)
"No such file or directory",
"export: Variable identifier (name) invalid",
"unset: Variable identifier (name) invalid",
"cd: too many arguments",
//"pwd : erreur de détermination du répertoire actuel : getcwd : ne peut accéder aux répertoires parents : Aucun fichier ou dossier de ce type",
"exit: too many arguments"};
......@@ -53,8 +54,9 @@ static int err_output(int err_code)
"Memory allocation failure",
"Cannot write on standard output",
"Cannot read standard input (GNL error)",
"cd",
"pwd",
"cd: cannot change directory",
"cd: cannot set variable PWD",
"pwd: cannot get current directory path",
"fd"};
ft_putstr_fd("error: ", STDERR_FILENO);
......
......@@ -76,7 +76,7 @@ int exec_env_init(t_xe *xe, char **env_source)
shlvl = ft_itoa(tmp);
if (shlvl == NULL)
return (MALLOC_ERR);
env_replace_var(SHLVL_STR, shlvl, xe);
env_replace_var(SHLVL_STR, shlvl, xe); // err
free(shlvl);
xe->backup_stdin = dup(STDIN_FILENO);
xe->backup_stdout = dup(STDOUT_FILENO);
......
......@@ -52,7 +52,7 @@ int env_replace_var(char *var_name, char *value, t_xe *xe)
// printf("shlvl = %d\n", tmp);
ft_export(new, xe);
free_str_array(new);
return (0);
return (SUCCESS);
}
int check_var_name(char *var, ssize_t name_len)
......
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