diff options
-rw-r--r-- | src/ft_e_lcom.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/ft_e_lcom.c b/src/ft_e_lcom.c index acfc187..36fb430 100644 --- a/src/ft_e_lcom.c +++ b/src/ft_e_lcom.c @@ -31,11 +31,12 @@ static uint8_t return (i); } +#include <stdio.h> uint8_t ft_e_lcom(t_msh *msh) { - int fd; t_lcom *ptr; + int32_t write_fd; uint8_t bu_id; ptr = msh->curr; @@ -44,13 +45,19 @@ uint8_t if ((bu_id = ft_get_builtin_id(ptr->com, msh)) < FT_BUILTINS_COUNT) { - if (ptr->redir == 1 && - (fd = open(ptr->rdrpath, O_CREAT | O_WRONLY, 0644))) + if (ptr->redir == 1) { - dup2(fd, STDOUT_FILENO); + if ((write_fd = open(ptr->rdrpath, O_CREAT | O_RDWR, 0644))) + { + /* TODO: handle err */ + } + dup2(write_fd, STDOUT_FILENO); } msh->ret = msh->bu_ptr[bu_id](ptr->args, msh); - close(fd); + if (ptr->redir == 1) + { + close(write_fd); + } } else { |