summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-23 00:28:59 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-23 00:28:59 +0200
commit6647c2b82dfe2ffc1efd7dd99590c54ad06d85af (patch)
tree67dfec3e56ce1ba21d2c119ac43dfeeadfcc4cbd /src
parentGood (diff)
download42-minishell-6647c2b82dfe2ffc1efd7dd99590c54ad06d85af.tar.gz
42-minishell-6647c2b82dfe2ffc1efd7dd99590c54ad06d85af.tar.bz2
42-minishell-6647c2b82dfe2ffc1efd7dd99590c54ad06d85af.tar.xz
42-minishell-6647c2b82dfe2ffc1efd7dd99590c54ad06d85af.tar.zst
42-minishell-6647c2b82dfe2ffc1efd7dd99590c54ad06d85af.zip
Now time to pipe(2)
Diffstat (limited to '')
-rw-r--r--src/ft_e_lcom.c2
-rw-r--r--src/ft_p_lcom.c32
2 files changed, 30 insertions, 4 deletions
diff --git a/src/ft_e_lcom.c b/src/ft_e_lcom.c
index 69cdf35..e8787da 100644
--- a/src/ft_e_lcom.c
+++ b/src/ft_e_lcom.c
@@ -45,7 +45,7 @@ uint8_t
}
else
{
- /* TODO: exec path stuff */
+ /* TODO: exec $PATH stuff */
}
ptr = ptr->next;
}
diff --git a/src/ft_p_lcom.c b/src/ft_p_lcom.c
index 5890b0f..aec344f 100644
--- a/src/ft_p_lcom.c
+++ b/src/ft_p_lcom.c
@@ -13,13 +13,39 @@
#include <libft.h>
#include <stdlib.h>
#include <stdint.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
#include "ft_s_lcom.h"
#include "ft_s_struct.h"
-void
- ft_check_redir_file()
+static void
+ ft_check_redir_file(t_lcom **link)
{
+ int32_t fd;
+ fd = 0;
+ if ((*link)->redir == -1 && (fd = open((*link)->rdrpath, O_RDONLY)) == -1)
+ {
+ /* TODO: better error handling | DON'T EXEC CMD | retval 1 */
+ if (errno == ENOENT)
+ ft_dprintf(STDERR_FILENO,
+ "minishell: %s: No such file or directory\n", (*link)->rdrpath);
+ else if (errno == EACCES)
+ ft_dprintf(STDERR_FILENO,
+ "minishell: %s: Permission denied\n", (*link)->rdrpath);
+ return ;
+ }
+ else if ((*link)->redir == 1
+ && (fd = open((*link)->rdrpath, O_CREAT | O_WRONLY, 0644)) == -1)
+ {
+ /* TODO: same as above */
+ if (errno == EACCES)
+ ft_dprintf(STDERR_FILENO,
+ "minishell: %s: Permission denied\n", (*link)->rdrpath);
+ }
+ /* TODO: >> redir file check */
+ close(fd);
}
static void
@@ -92,6 +118,7 @@ int8_t
ft_rdr_err_check(ptr, link);
if (ft_get_rdrpath(ptr, link) != 0)
return (-1);
+ ft_check_redir_file(link);
}
return (0);
}
@@ -115,7 +142,6 @@ int8_t
return (-1);
}
ft_lcom_add_back(&msh->curr, link);
- ft_printf("%s\n", msh->curr->rdrpath);
i++;
}
ft_delwords(words);