diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-04 15:52:47 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-04 15:52:47 +0200 |
commit | 5cb3373a2e5a5109a5d3b72ef45978b98f885706 (patch) | |
tree | 11a0a6f467da3ddf227d2eaf6824c4509242025e /src/e_externs.c | |
parent | ok nice (diff) | |
parent | $? fix (diff) | |
download | 42-minishell-5cb3373a2e5a5109a5d3b72ef45978b98f885706.tar.gz 42-minishell-5cb3373a2e5a5109a5d3b72ef45978b98f885706.tar.bz2 42-minishell-5cb3373a2e5a5109a5d3b72ef45978b98f885706.tar.xz 42-minishell-5cb3373a2e5a5109a5d3b72ef45978b98f885706.tar.zst 42-minishell-5cb3373a2e5a5109a5d3b72ef45978b98f885706.zip |
Merge branch 'master' into fix-pwd
Diffstat (limited to '')
-rw-r--r-- | src/e_externs.c (renamed from src/ft_e_externs.c) | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/ft_e_externs.c b/src/e_externs.c index 9302d18..93d989f 100644 --- a/src/ft_e_externs.c +++ b/src/e_externs.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_e_externs.c :+: :+: :+: */ +/* e_externs.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -16,24 +16,25 @@ #include <stdint.h> #include <unistd.h> -#include "ft_e_externs_next.h" -#include "ft_m_redirs.h" -#include "ft_s_destroy.h" -#include "ft_s_lcom.h" -#include "ft_s_struct.h" +#include "e_externs_next.h" +#include "f_fail.h" +#include "m_redirs.h" +#include "s_destroy.h" +#include "s_lcom.h" +#include "s_struct.h" static void - ft_e_extern_child(const char *fullpath, + e_extern_child(const char *fullpath, t_lcom *ptr, t_msh *msh) { - ft_dup_redirs(ptr, msh); + dup_redirs(ptr, msh); execve(fullpath, ptr->argv, msh->envp); /* TODO: handle execve failed */ } static void - ft_exec_path(const char fullpath[], + exec_path(const char fullpath[], t_lcom *ptr, t_msh *msh) { @@ -42,7 +43,7 @@ static void if ((pid = fork()) == 0) { - ft_e_extern_child(fullpath, ptr, msh); + e_extern_child(fullpath, ptr, msh); } else if (pid < 0) { @@ -57,7 +58,7 @@ static void } void - ft_e_extern(t_lcom *ptr, + e_extern(t_lcom *ptr, t_msh *msh) { char **envpath; @@ -65,15 +66,21 @@ void if (ft_ischarset("/.", ptr->com[0])) { - ft_exec_path(ptr->com, ptr, msh); + exec_path(ptr->com, ptr, msh); return ; } - else if ((envpath = ft_get_env_path(msh)) != NULL) + else if ((envpath = get_env_path(msh)) != NULL) { - fullpath = ft_search_in_path(ptr->com, envpath, msh); + fullpath = search_in_path(ptr->com, envpath, msh); ft_delwords(envpath); + if (fullpath == NULL) + { + f_fail_command_not_found(ptr->com); + } + else + { + exec_path(fullpath, ptr, msh); + ft_memdel((void*)&fullpath); + } } - /* TODO: deal if not found etc */ - ft_exec_path(fullpath, ptr, msh); - ft_memdel((void*)&fullpath); } |