diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-23 02:13:49 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-23 02:13:49 +0200 |
commit | eb3c8d6b29d52f7224240295108f0b133677fba2 (patch) | |
tree | 225da65c0678466e6ebb415d55df762b5e85f876 /src/ft_e_lcom.c | |
parent | nigga be eating my prompt (diff) | |
download | 42-minishell-eb3c8d6b29d52f7224240295108f0b133677fba2.tar.gz 42-minishell-eb3c8d6b29d52f7224240295108f0b133677fba2.tar.bz2 42-minishell-eb3c8d6b29d52f7224240295108f0b133677fba2.tar.xz 42-minishell-eb3c8d6b29d52f7224240295108f0b133677fba2.tar.zst 42-minishell-eb3c8d6b29d52f7224240295108f0b133677fba2.zip |
It's not working at all
Diffstat (limited to 'src/ft_e_lcom.c')
-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 { |