summaryrefslogtreecommitdiffstats
path: root/src/e_externs.c
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-10-26 13:42:56 +0100
committersalad <fmoenne-@student.le-101.fr>2020-10-26 13:42:56 +0100
commit0277ddfac754ab4ad5bdd2b692e31a717efbe569 (patch)
tree49d7c5fd3a12248af85e2c3a3254bc1538ae5775 /src/e_externs.c
parentreqdy for MERGE (diff)
parentTODO update (diff)
download42-minishell-0277ddfac754ab4ad5bdd2b692e31a717efbe569.tar.gz
42-minishell-0277ddfac754ab4ad5bdd2b692e31a717efbe569.tar.bz2
42-minishell-0277ddfac754ab4ad5bdd2b692e31a717efbe569.tar.xz
42-minishell-0277ddfac754ab4ad5bdd2b692e31a717efbe569.tar.zst
42-minishell-0277ddfac754ab4ad5bdd2b692e31a717efbe569.zip
merge wif master
Diffstat (limited to 'src/e_externs.c')
-rw-r--r--src/e_externs.c47
1 files changed, 18 insertions, 29 deletions
diff --git a/src/e_externs.c b/src/e_externs.c
index 9e2f8f4..8761986 100644
--- a/src/e_externs.c
+++ b/src/e_externs.c
@@ -16,28 +16,30 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <limits.h>
#include <errno.h>
#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
e_extern_child(const char *fullpath,
- t_com *ptr,
- t_msh *msh)
+ t_com *ptr,
+ t_msh *msh)
{
- dup_redirs(ptr, msh);
if (execve(fullpath, ptr->argv, msh->envp) == -1)
{
- f_exec(fullpath);
- ft_memdel((void*)&fullpath);
- u_eof_stdin();
+ 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);
@@ -59,7 +61,7 @@ static void
}
static void
- exec_path(const char fullpath[],
+ e_exec_path(const char fullpath[],
t_com *ptr,
t_msh *msh)
{
@@ -84,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 ;
- exec_path(fullpath, ptr, msh);
- ft_memdel((void*)&fullpath);
+ ft_strlcpy(fullpath, ptr->bin, PATH_MAX);
+ e_exec_path(fullpath, ptr, msh);
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
- {
- 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);
}
}