diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-19 17:14:56 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-19 17:14:56 +0200 |
commit | 767b1cceaf1487dde84dcff3c0b58cadbce61d21 (patch) | |
tree | 97cf1f7e7ae9f0308faf3654d922fe2664548acf /src | |
parent | Cleaner variables handling $0 $1 $2 $3 (diff) | |
download | 42-minishell-767b1cceaf1487dde84dcff3c0b58cadbce61d21.tar.gz 42-minishell-767b1cceaf1487dde84dcff3c0b58cadbce61d21.tar.bz2 42-minishell-767b1cceaf1487dde84dcff3c0b58cadbce61d21.tar.xz 42-minishell-767b1cceaf1487dde84dcff3c0b58cadbce61d21.tar.zst 42-minishell-767b1cceaf1487dde84dcff3c0b58cadbce61d21.zip |
Good luck have fuck
Diffstat (limited to '')
-rw-r--r-- | src/m_redirs.c | 23 | ||||
-rw-r--r-- | src/p_lblock.c | 5 | ||||
-rw-r--r-- | src/s_struct.h | 2 |
3 files changed, 18 insertions, 12 deletions
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 <libft.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> @@ -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); } diff --git a/src/p_lblock.c b/src/p_lblock.c index 377757d..3acae1a 100644 --- a/src/p_lblock.c +++ b/src/p_lblock.c @@ -86,7 +86,6 @@ static void int8_t p_get_redir(const char word[], t_com **com) { - /* TODO: norme */ char *ptr; ptr = (char *)word; @@ -103,9 +102,7 @@ int8_t break ; } ptr++; - /* TODO: handle correctly multiples "msh ~> echo qwe > qwe > asd >> zxc > qweasdzxc" */ - /* hint: bash only handles the last one */ - /* TODO: handle "msh ~> cat < Makefile >qwe" | gl hf */ + /* gl hf */ } if ((*com)->redir > 0) { diff --git a/src/s_struct.h b/src/s_struct.h index f47eda0..84271de 100644 --- a/src/s_struct.h +++ b/src/s_struct.h @@ -46,8 +46,8 @@ typedef struct s_com { char **argv; char **env_fork; - char *rdrpath; char *bin; + char *rdrpath; int32_t rdrfd; int8_t redir; } t_com; |