/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* e_unshebanged.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #ifdef __linux__ # include #else # include #endif #include #include "f_fail.h" #include "s_struct.h" #include "s_com.h" #include "s_destroy.h" #include "s_line.h" #include "s_lpipes.h" #include "u_utils.h" static char **e_get_new_argv(const char fullpath[], t_com *ptr, t_msh *msh) { char **argv; size_t i; if ((argv = (char**)malloc((3 + u_builtins_get_argc((const char**)ptr->argv)) * sizeof(char*))) == NULL) f_alloc_and_destroy_msh(msh); if ((argv[0] = ft_strdup(msh->argv[0])) == NULL || (argv[1] = ft_strdup(fullpath)) == NULL) { ft_memdel((void*)&argv); f_alloc_and_destroy_msh(msh); } i = 2; while (ptr->argv[i - 2] != NULL) { if ((argv[i] = ft_strdup(ptr->argv[i - 2])) == NULL) { ft_memdel((void*)&argv); f_alloc_and_destroy_msh(msh); } i++; } argv[i] = NULL; return (argv); } void e_extern_read_script(const char fullpath[], t_com *ptr, t_msh *msh, t_bool pipe) { char **argv; argv = e_get_new_argv(fullpath, ptr, msh); if (execve(msh->argv[0], (char* const *)argv, msh->envp) == -1) { f_exec(msh->argv[0], argv[0]); ft_delwords(argv); u_eof_fd(msh->fd); s_com_destroy(&msh->com); if (pipe == TRUE) s_lpipes_clear(&msh->pipes); s_line_clear(&msh->curr); s_destroy(msh); exit(errno); } }