From eb3c8d6b29d52f7224240295108f0b133677fba2 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 23 Apr 2020 02:13:49 +0200 Subject: It's not working at all --- src/ft_e_lcom.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/ft_e_lcom.c') 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 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 { -- cgit v1.2.3