diff --git a/src/ak_pipe.c b/src/ak_pipe.c index 461b121..a815791 100644 --- a/src/ak_pipe.c +++ b/src/ak_pipe.c @@ -16,10 +16,10 @@ void child(int fd[2], t_data *data, int i) { close(fd[0]); if (dup2(data->hermes, STDIN_FILENO) == -1) - return (perror("pipex1"), clear_exit(data, EXIT_FAILURE)); + return (perror("pipex"), clear_exit(data, EXIT_FAILURE)); close(data->hermes); if (dup2(fd[1], STDOUT_FILENO) == -1) - return (perror("pipex2"), clear_exit(data, EXIT_FAILURE)); + return (perror("pipex"), clear_exit(data, EXIT_FAILURE)); close(fd[1]); cmd_exe(data); } @@ -31,10 +31,10 @@ void ak_pipe(t_data *data, int i) if (data->first == -1 && i == 2) return ; if (pipe(fd) == -1) - return (perror("pipex3"), clear_exit(data, EXIT_FAILURE)); + return (perror("pipex"), clear_exit(data, EXIT_FAILURE)); data->ids[i - (2 + data->here_doc)] = fork(); if (data->ids[i - (2 + data->here_doc)] < 0) - return (perror("pipex4"), clear_exit(data, EXIT_FAILURE)); + return (perror("pipex"), clear_exit(data, EXIT_FAILURE)); if (!data->ids[i - (2 + data->here_doc)]) child(fd, data, i); close(fd[1]); diff --git a/src/ak_pipeout.c b/src/ak_pipeout.c index f108e7e..8b75c36 100644 --- a/src/ak_pipeout.c +++ b/src/ak_pipeout.c @@ -6,7 +6,7 @@ /* By: akdovlet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/15 03:05:49 by akdovlet #+# #+# */ -/* Updated: 2024/05/15 03:06:25 by akdovlet ### ########.fr */ +/* Updated: 2024/05/15 05:06:13 by akdovlet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,16 @@ void child_out(t_data *data) cmd_exe(data); } +void open_outfile(t_data *data) +{ + if (data->here_doc) + data->last = data->last = open(data->av[data->ac - 1], \ + O_WRONLY | O_CREAT | O_APPEND, 0644); + else + data->last = open(data->av[data->ac - 1], \ + O_WRONLY | O_CREAT | O_TRUNC, 0644); +} + void ak_pipeout(t_data *data, int i) { int status; @@ -30,8 +40,7 @@ void ak_pipeout(t_data *data, int i) j = 0; status = 0; - data->last = open(data->av[data->ac - 1], \ - O_WRONLY | O_CREAT | O_TRUNC, 0644); + open_outfile(data); if (data->last < 0) return (perror(data->av[data->ac -1]), clear_exit(data, EXIT_FAILURE)); data->ids[i - (2 + data->here_doc)] = fork();