diff options
Diffstat (limited to '')
-rw-r--r-- | src/e_redirs.c | 16 | ||||
-rw-r--r-- | src/s_lredir.c | 2 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/e_redirs.c b/src/e_redirs.c index b07026f..6bb600f 100644 --- a/src/e_redirs.c +++ b/src/e_redirs.c @@ -15,23 +15,25 @@ #include <stddef.h> #include <fcntl.h> #include <unistd.h> -#include <stdio.h> #include "f_fail.h" #include "s_destroy.h" #include "s_line.h" #include "s_struct.h" -static void e_redir_minus_two(struct s_lredir *ptr, t_msh *msh) +static void e_redir_minus_two(struct s_lredir *ptr) { - (void)msh; + int32_t fd[2]; + if (ptr->heredoc == NULL) { return ; } - dup2(STDOUT_FILENO, STDIN_FILENO); - write(STDOUT_FILENO, ptr->heredoc, ft_strlen(ptr->heredoc) + 1); - close(STDIN_FILENO); + pipe(fd); + dup2(fd[0], STDIN_FILENO); + ft_dprintf(fd[1], "%s", ptr->heredoc); + close(fd[1]); + close(fd[0]); } static void e_redir_minus_one(struct s_lredir *ptr, t_msh *msh) @@ -82,7 +84,7 @@ void e_dup_redirs(const t_com *com, t_msh *msh) { if (ptr->redir == -2) { - e_redir_minus_two(ptr, msh); + e_redir_minus_two(ptr); } else if (ptr->redir == -1) { diff --git a/src/s_lredir.c b/src/s_lredir.c index 1aae3be..84e857c 100644 --- a/src/s_lredir.c +++ b/src/s_lredir.c @@ -52,6 +52,8 @@ void s_lredir_clear(struct s_lredir **lredir) while (tmp != NULL) { renext = tmp->next; + if (tmp->heredoc != NULL) + ft_memdel((void*)&tmp->heredoc); ft_memdel((void*)&tmp); tmp = renext; } |