Commit 997e7205 authored by abenoit's avatar abenoit
Browse files

cd get_var_pos instead of var_value, stat loc set when PATH and HO:E error

parent 74ae5b70
......@@ -13,7 +13,7 @@
enum e_exec_errcode
{
HOME_NOT_SET = 7,
FILE_NOT_FOUND
NO_SUCH_FILE
};
enum e_cmd_code
......@@ -52,7 +52,7 @@ int ft_env(char **args, t_xe *xe);
** utils
*/
int exec_error(int err_code);
int exec_error(int err_code, t_xe *xe);
/*
** utils
......
#include "execution.h"
int exec_error(int err_code)
int exec_error(int err_code, t_xe *xe)
{
const char *err_msg[] = {
"HOME not set",
......@@ -8,8 +8,12 @@ int exec_error(int err_code)
(void)err_msg;
ft_putstr_fd("minishell: command error: ", STDERR_FILENO);
ft_putstr_fd(err_msg[err_code], STDERR_FILENO);
ft_putstr_fd(err_msg[err_code - 7], STDERR_FILENO);
ft_putchar_fd('\n', STDERR_FILENO);
// have to set stat_loc as well !!!
if (err_code == HOME_NOT_SET)
xe->stat_loc = 1;
if (err_code == NO_SUCH_FILE)
xe->stat_loc = 127;
return (SUCCESS);
}
......@@ -4,14 +4,16 @@
int ft_cd(char **args, t_xe *xe)
{
int ret;
char *path;
char *oldpwd;
if (args[1] == NULL)
{
path = get_var_value(xe->env, "HOME", 4);
if (path == NULL)
ret = get_var_pos(xe->env, "HOME", 4);
if (ret == -1)
return (HOME_NOT_SET);
path = get_var_value(xe->env, "HOME", 4);
}
else
path = ft_strdup(args[1]);
......
......@@ -66,7 +66,7 @@ static int child_task(char **path, char **args, t_xe *xe)
if (dir_index == NOT_FOUND)
{
free_str_array(path);
return (FILE_NOT_FOUND); // other error code
return (NO_SUCH_FILE); // other error code
}
cmd = ft_strjoin(path[dir_index], "/");
cmd = ft_strjoin(cmd, args[0]);
......@@ -187,7 +187,7 @@ int execute_cmd(char **args, char **redir_paths, enum e_redir_op *redir_types,
return (MALLOC_ERR);
ret = command[cmd_code](args, xe);
if (ret >= HOME_NOT_SET)
return (exec_error(ret - 7));
return (exec_error(ret, xe));
free_str_array(args);
return (ret);
}
Supports Markdown
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