diff options
Diffstat (limited to '')
-rw-r--r-- | src/ft_e_lcom.c | 2 | ||||
-rw-r--r-- | src/ft_p_lcom.c | 32 |
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); |