diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-23 13:18:26 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-23 13:18:26 +0200 |
commit | e903e645727171e845c75593f12e57c8d7cbb582 (patch) | |
tree | 905cbdc26230ffa0af4bcc7c7f293038a041fafb | |
parent | Omg (diff) | |
download | 42-minishell-e903e645727171e845c75593f12e57c8d7cbb582.tar.gz 42-minishell-e903e645727171e845c75593f12e57c8d7cbb582.tar.bz2 42-minishell-e903e645727171e845c75593f12e57c8d7cbb582.tar.xz 42-minishell-e903e645727171e845c75593f12e57c8d7cbb582.tar.zst 42-minishell-e903e645727171e845c75593f12e57c8d7cbb582.zip |
It's working but not quited perfect with >>
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | src/ft_e_lcom.c | 20 |
2 files changed, 17 insertions, 6 deletions
@@ -125,4 +125,5 @@ flycheck_*.el minishell minishell_history *.core -vgcore*
\ No newline at end of file +vgcore* +qwe
\ No newline at end of file diff --git a/src/ft_e_lcom.c b/src/ft_e_lcom.c index 5bffe0a..dab8f95 100644 --- a/src/ft_e_lcom.c +++ b/src/ft_e_lcom.c @@ -39,7 +39,7 @@ uint8_t { /* TODO: norme */ t_lcom *ptr; - int32_t write_fd; + int32_t fd; int32_t status; uint8_t bu_id; pid_t pid; @@ -52,15 +52,25 @@ uint8_t { if ((pid = fork()) == 0) { + fd = 0; + ft_printf("%hhd\n", ptr->redir); if (ptr->redir == 1) { - if ((write_fd = open(ptr->rdrpath, O_CREAT | O_RDWR, 0644))) + if ((fd = open(ptr->rdrpath, O_CREAT | O_RDWR, 0644))) { - /* TODO: handle err */ + /* TODO: handle err with errno */ } - dup2(write_fd, STDOUT_FILENO); - close(write_fd); + /* TODO: erase file and write */ } + else if (ptr->redir == 2) + { + if ((fd = open(ptr->rdrpath, O_CREAT | O_RDWR | O_APPEND, 0644))) + { + /* TODO: handle err with errno */ + } + } + dup2(fd, STDOUT_FILENO); + close(fd); msh->ret = msh->bu_ptr[bu_id](ptr->args, msh); exit(msh->ret); } |