Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Benoit
minishell
Commits
997e7205
Commit
997e7205
authored
Jan 21, 2021
by
abenoit
Browse files
cd get_var_pos instead of var_value, stat loc set when PATH and HO:E error
parent
74ae5b70
Changes
4
Hide whitespace changes
Inline
Side-by-side
inc/execution.h
View file @
997e7205
...
...
@@ -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
...
...
src/execution/exec_error.c
View file @
997e7205
#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
);
}
src/execution/ft_cd.c
View file @
997e7205
...
...
@@ -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
]);
...
...
src/execution/launch_command.c
View file @
997e7205
...
...
@@ -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
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment