Skip to content

Commit

Permalink
c'est all night long
Browse files Browse the repository at this point in the history
  • Loading branch information
akdovlet committed May 15, 2024
1 parent d90e7e7 commit da3cda9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/ak_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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]);
Expand Down
15 changes: 12 additions & 3 deletions src/ak_pipeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: akdovlet <akdovlet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -23,15 +23,24 @@ 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;
int j;

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();
Expand Down

0 comments on commit da3cda9

Please sign in to comment.