summaryrefslogtreecommitdiffstats
path: root/src/e_externs.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-15 19:59:41 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-15 19:59:41 +0200
commitca2e36781039eb7e9901ccde395600e7af87ff4f (patch)
tree8a9d85433e943fbbd079bc55700e048a54d9bf24 /src/e_externs.c
parenttype builtin fix (diff)
download42-minishell-ca2e36781039eb7e9901ccde395600e7af87ff4f.tar.gz
42-minishell-ca2e36781039eb7e9901ccde395600e7af87ff4f.tar.bz2
42-minishell-ca2e36781039eb7e9901ccde395600e7af87ff4f.tar.xz
42-minishell-ca2e36781039eb7e9901ccde395600e7af87ff4f.tar.zst
42-minishell-ca2e36781039eb7e9901ccde395600e7af87ff4f.zip
Huge fixes and stack stuff
Diffstat (limited to '')
-rw-r--r--src/e_externs.c36
1 files changed, 13 insertions, 23 deletions
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 <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
@@ -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);
}
}