From ca2e36781039eb7e9901ccde395600e7af87ff4f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 15 Sep 2020 19:59:41 +0200 Subject: Huge fixes and stack stuff --- src/e_externs.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'src/e_externs.c') diff --git a/src/e_externs.c b/src/e_externs.c index 253d758..8761986 100644 --- a/src/e_externs.c +++ b/src/e_externs.c @@ -16,15 +16,18 @@ #include #include #include +#include #include #include "b_export_next.h" -#include "e_externs_next.h" +#include "d_define.h" #include "f_fail.h" #include "m_redirs.h" +#include "s_com.h" #include "s_destroy.h" #include "s_line.h" #include "s_struct.h" +#include "u_path.h" #include "u_utils.h" static void @@ -34,9 +37,9 @@ static void { if (execve(fullpath, ptr->argv, msh->envp) == -1) { - f_exec(fullpath); - ft_memdel((void*)&fullpath); + f_exec(fullpath, ptr->bin); u_eof_fd(msh->fd); + s_com_destroy(&msh->com); s_line_clear(&msh->curr); s_destroy(msh); exit(errno); @@ -83,33 +86,20 @@ static void } } -void - e_extern(t_com *ptr, - t_msh *msh) +void e_extern(t_com *ptr, t_msh *msh) { - char **envpath; - char *fullpath; + char fullpath[PATH_MAX]; + fullpath[0] = C_NUL; if (ft_ischarset("./", ptr->bin[0]) == TRUE) { - if ((fullpath = ft_strdup(ptr->bin)) == NULL) - return ; + ft_strlcpy(fullpath, ptr->bin, PATH_MAX); e_exec_path(fullpath, ptr, msh); - ft_memdel((void*)&fullpath); return ; } - else if ((envpath = get_env_path(msh)) != NULL) + else { - fullpath = search_in_path(ptr->bin, envpath, msh); - ft_delwords(envpath); - if (fullpath == NULL) - { - f_fail_command_not_found(ptr->bin, msh); - } - else - { - e_exec_path(fullpath, ptr, msh); - ft_memdel((void*)&fullpath); - } + u_search_in_path(fullpath, ptr->bin, PATH_MAX, msh); + e_exec_path(fullpath, ptr, msh); } } -- cgit v1.2.3