diff --git a/.cache/clangd/index/exec.c.0790F7FFBBA14DB7.idx b/.cache/clangd/index/exec.c.0790F7FFBBA14DB7.idx new file mode 100644 index 0000000..eff1060 Binary files /dev/null and b/.cache/clangd/index/exec.c.0790F7FFBBA14DB7.idx differ diff --git a/.cache/clangd/index/exec.h.37CB144F896E9007.idx b/.cache/clangd/index/exec.h.37CB144F896E9007.idx new file mode 100644 index 0000000..5700365 Binary files /dev/null and b/.cache/clangd/index/exec.h.37CB144F896E9007.idx differ diff --git a/.cache/clangd/index/ft_freearr.c.702B21921D406A5C.idx b/.cache/clangd/index/ft_freearr.c.702B21921D406A5C.idx new file mode 100644 index 0000000..f7d048d Binary files /dev/null and b/.cache/clangd/index/ft_freearr.c.702B21921D406A5C.idx differ diff --git a/.cache/clangd/index/ft_senderror.c.513E04A6E4E254EB.idx b/.cache/clangd/index/ft_senderror.c.513E04A6E4E254EB.idx new file mode 100644 index 0000000..09f20a1 Binary files /dev/null and b/.cache/clangd/index/ft_senderror.c.513E04A6E4E254EB.idx differ diff --git a/.cache/clangd/index/getpath.c.E59496E4AC65B437.idx b/.cache/clangd/index/getpath.c.E59496E4AC65B437.idx new file mode 100644 index 0000000..fbabaeb Binary files /dev/null and b/.cache/clangd/index/getpath.c.E59496E4AC65B437.idx differ diff --git a/.cache/clangd/index/main.c.259C23514E408AC0.idx b/.cache/clangd/index/main.c.259C23514E408AC0.idx index 4b79579..be2763a 100644 Binary files a/.cache/clangd/index/main.c.259C23514E408AC0.idx and b/.cache/clangd/index/main.c.259C23514E408AC0.idx differ diff --git a/.cache/clangd/index/set_path.c.DE8818CAB0FB9AD3.idx b/.cache/clangd/index/set_path.c.DE8818CAB0FB9AD3.idx new file mode 100644 index 0000000..76e9791 Binary files /dev/null and b/.cache/clangd/index/set_path.c.DE8818CAB0FB9AD3.idx differ diff --git a/Makefile b/Makefile index 1cb6e1f..1dc51d8 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: adjoly +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/01 11:03:22 by adjoly #+# #+# # -# Updated: 2024/03/28 21:59:20 by adjoly ### ########.fr # +# Updated: 2024/04/08 15:21:46 by adjoly ### ########.fr # # # # **************************************************************************** # diff --git a/compile_commands.json b/compile_commands.json deleted file mode 100644 index 30dade1..0000000 --- a/compile_commands.json +++ /dev/null @@ -1,59 +0,0 @@ -[ - { - "directory": "/nfs/homes/adjoly/Documents/pipex", - "arguments": [ - "cc", - "-I", - "include/", - "-I", - "libft/", - "-Werror", - "-Wall", - "-Wextra", - "-g", - "src/main.c", - "-c", - "-o", - "obj/src/main.o" - ], - "file": "src/main.c" - }, - { - "directory": "/nfs/homes/adjoly/Documents/pipex", - "arguments": [ - "cc", - "-I", - "include/", - "-I", - "libft/", - "-Werror", - "-Wall", - "-Wextra", - "-g", - "src/parsing/parsing.c", - "-c", - "-o", - "obj/src/parsing/parsing.o" - ], - "file": "src/parsing/parsing.c" - }, - { - "directory": "/nfs/homes/adjoly/Documents/pipex", - "arguments": [ - "cc", - "-I", - "include/", - "-I", - "libft/", - "-Werror", - "-Wall", - "-Wextra", - "-g", - "src/utils/ft_freetab.c", - "-c", - "-o", - "obj/src/utils/ft_freetab.o" - ], - "file": "src/utils/ft_freetab.c" - } -] diff --git a/obj/src/exec/exec.o b/obj/src/exec/exec.o new file mode 100644 index 0000000..9725551 Binary files /dev/null and b/obj/src/exec/exec.o differ diff --git a/obj/src/main.o b/obj/src/main.o new file mode 100644 index 0000000..ba53740 Binary files /dev/null and b/obj/src/main.o differ diff --git a/obj/src/parsing/parsing.o b/obj/src/parsing/parsing.o new file mode 100644 index 0000000..ee7283f Binary files /dev/null and b/obj/src/parsing/parsing.o differ diff --git a/obj/src/utils/ft_freearr.o b/obj/src/utils/ft_freearr.o new file mode 100644 index 0000000..2f98361 Binary files /dev/null and b/obj/src/utils/ft_freearr.o differ diff --git a/obj/src/utils/ft_senderror.o b/obj/src/utils/ft_senderror.o new file mode 100644 index 0000000..3fabcdb Binary files /dev/null and b/obj/src/utils/ft_senderror.o differ diff --git a/obj/src/utils/getpath.o b/obj/src/utils/getpath.o new file mode 100644 index 0000000..2966683 Binary files /dev/null and b/obj/src/utils/getpath.o differ diff --git a/obj/src/utils/set_path.o b/obj/src/utils/set_path.o new file mode 100644 index 0000000..7f3f604 Binary files /dev/null and b/obj/src/utils/set_path.o differ diff --git a/pipex b/pipex new file mode 100755 index 0000000..3b2a761 Binary files /dev/null and b/pipex differ diff --git a/src/exec/exec.c b/src/exec/exec.c index f72543a..ec8eac5 100644 --- a/src/exec/exec.c +++ b/src/exec/exec.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/06 14:07:27 by adjoly #+# #+# */ -/* Updated: 2024/04/07 11:01:39 by adjoly ### ########.fr */ +/* Updated: 2024/04/08 14:09:14 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -63,10 +63,11 @@ pid_t ft_exec_scnd_pipe(t_pipex *pipex, int fd[2]) { outfile = open(pipex->outfile, O_CREAT | O_WRONLY | O_TRUNC, 0644); dup2(fd[0], STDIN_FILENO); + close(fd[0]); dup2(outfile, STDOUT_FILENO); close(outfile); - close(fd[0]); close(fd[1]); + close(pipex->infile); execve(pipex->cmd[1].cmd, pipex->cmd[1].option, pipex->env); } return (pid); diff --git a/src/main.c b/src/main.c index e14c69a..5c40d93 100644 --- a/src/main.c +++ b/src/main.c @@ -6,13 +6,35 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/21 10:03:04 by adjoly #+# #+# */ -/* Updated: 2024/04/08 12:49:21 by adjoly ### ########.fr */ +/* Updated: 2024/04/08 15:26:06 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" #include "parsing.h" #include "pipex.h" +#include + +void check_cmd_validity(t_pipex *pipex) +{ + t_pcmd *cmd; + + cmd = pipex->cmd; + while (cmd) + { + if (access(cmd->cmd, X_OK) != 0) + { + // ft_freearr((*cmd).option); + // if (pipex->cmd[1].cmd) + // { + // ft_freearr(pipex->cmd[1].option); + // free(pipex->cmd[1].cmd); + // } + ft_senderror(pipex, "Error: Command not found"); + } + cmd++; + } +} void check_empty_args(char **av, t_pipex *pipex) { @@ -71,9 +93,10 @@ int main(int ac, char **av, char **env) pipex->cmd = parse_cmd(ac - 3, av); pipex->env = env; getpath(pipex); - if (pipex->path == NULL) - ft_senderror(pipex, "Error : Can't find path"); - get_arrcmd_path(pipex); + if (pipex->path) + get_arrcmd_path(pipex); + else + check_cmd_validity(pipex); exec_pipe(pipex); ft_freearr(pipex->path); free_pcmd(pipex->cmd); diff --git a/src/utils/getpath.c b/src/utils/getpath.c index 478c34f..8aa595b 100644 --- a/src/utils/getpath.c +++ b/src/utils/getpath.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/04 15:32:56 by adjoly #+# #+# */ -/* Updated: 2024/04/07 16:20:05 by adjoly ### ########.fr */ +/* Updated: 2024/04/08 14:18:42 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/utils/set_path.c b/src/utils/set_path.c index 14f233d..d5012ac 100644 --- a/src/utils/set_path.c +++ b/src/utils/set_path.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/06 13:31:15 by adjoly #+# #+# */ -/* Updated: 2024/04/08 12:54:26 by adjoly ### ########.fr */ +/* Updated: 2024/04/08 14:39:01 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */