From 767b1cceaf1487dde84dcff3c0b58cadbce61d21 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 19 Sep 2020 17:14:56 +0200 Subject: Good luck have fuck --- src/m_redirs.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/m_redirs.c') diff --git a/src/m_redirs.c b/src/m_redirs.c index 91014bb..50e416a 100644 --- a/src/m_redirs.c +++ b/src/m_redirs.c @@ -10,6 +10,7 @@ /* */ /* ************************************************************************** */ +#include #include #include #include @@ -19,32 +20,40 @@ #include "s_line.h" #include "s_struct.h" -void - dup_redirs(const t_com *ptr, - t_msh *msh) +void dup_redirs(const t_com *ptr, t_msh *msh) { int32_t fd; if (ptr->redir == -1) { if ((fd = open(ptr->rdrpath, O_RDONLY)) == -1) + { f_redir(ptr->rdrpath, msh); + return ; + } + ft_printf("[%s]", ptr->rdrpath); dup2(fd, STDIN_FILENO); close(fd); } - if (ptr->redir == 1) + else if (ptr->redir == 1) { if ((fd = open(ptr->rdrpath, - O_CREAT | O_TRUNC | O_WRONLY, 0644)) == -1) + O_CREAT | O_TRUNC | O_WRONLY, 0644)) == -1) + { f_redir(ptr->rdrpath, msh); + return ; + } dup2(fd, ptr->rdrfd); close(fd); } - if (ptr->redir == 2) + else if (ptr->redir == 2) { if ((fd = open(ptr->rdrpath, - O_CREAT | O_APPEND | O_WRONLY, 0644)) == -1) + O_CREAT | O_APPEND | O_WRONLY, 0644)) == -1) + { f_redir(ptr->rdrpath, msh); + return ; + } dup2(fd, ptr->rdrfd); close(fd); } -- cgit v1.2.3