diff options
Diffstat (limited to '')
-rw-r--r-- | src/e_externs.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/e_externs.c b/src/e_externs.c index a3d3594..7b25516 100644 --- a/src/e_externs.c +++ b/src/e_externs.c @@ -15,6 +15,7 @@ #include <stdint.h> #include <stdlib.h> #include <string.h> +#include <fcntl.h> #include <unistd.h> #include <limits.h> #include <errno.h> @@ -23,6 +24,7 @@ #include "d_define.h" #include "f_fail.h" #include "e_redirs.h" +#include "e_unshebanged.h" #include "s_com.h" #include "s_destroy.h" #include "s_line.h" @@ -32,6 +34,21 @@ static void e_extern_child(const char fullpath[], t_com *ptr, t_msh *msh) { + char buff[7]; + int32_t fd; + + if ((fd = open(fullpath, O_RDONLY)) != -1) + { + if (read(fd, buff, 7) != -1) + if (ft_strncmp(buff, "\177ELF\002\001\001", 7) != 0 + && ft_strncmp(buff, "#!", 2) != 0) + { + close(fd); + e_extern_read_script(fullpath, ptr, msh, FALSE); + return ; + } + close(fd); + } if (execve(fullpath, ptr->argv, msh->envp) == -1) { f_exec(fullpath, ptr->bin); @@ -103,7 +120,8 @@ void e_extern(t_com *ptr, t_msh *msh) uint8_t fp_ret; fullpath[0] = C_NUL; - if (ft_ischarset("./", ptr->bin[0]) == TRUE) + if (ptr->bin != NULL && (ft_ischarset("./", ptr->bin[0]) == TRUE + || ft_strchr(ptr->bin, '/') != NULL)) { ft_strlcpy(fullpath, ptr->bin, PATH_MAX); e_exec_path(fullpath, ptr, 0, msh); |