summaryrefslogtreecommitdiffstats
path: root/src/ft_e_lcom.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_e_lcom.c20
1 files changed, 15 insertions, 5 deletions
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);
}