From f498fb6dbbeab4b2993b834a6abd41ba8c2ed316 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 22 Oct 2020 19:58:27 +0200 Subject: On the way but norm this shit --- src/s_lredir.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/s_lredir.c') diff --git a/src/s_lredir.c b/src/s_lredir.c index 109f313..b2e94e8 100644 --- a/src/s_lredir.c +++ b/src/s_lredir.c @@ -13,12 +13,14 @@ #include #include #include +#include #ifdef __linux__ # include #else # include #endif +#include "d_define.h" #include "s_struct.h" static t_lredir *s_lredir_last(struct s_lredir *lredir) @@ -66,8 +68,17 @@ void s_lredir_clear(struct s_lredir **lredir) static int32_t s_get_right_fd(const char path[]) { + char *ptr; int32_t rfd; + ptr = (char*)path; + while (ft_isdigit(*ptr) == TRUE) + ptr++; + if (*ptr != C_NUL) + { + ft_dprintf(STDERR_FILENO, "minishell: %s: ambigous redirect\n", path); + return (-1); + } rfd = 0; return (rfd); } @@ -80,8 +91,11 @@ struct s_lredir *s_lredir_new(const char path[], int32_t fd, int8_t redir) return (NULL); rdr->fd = fd; rdr->right_fd = -1; - if (redir == 3 && rdr->right_fd = s_get_right_fd(path) == -1) + if (redir == 3 && (rdr->right_fd = s_get_right_fd(path)) == -1) + { + ft_memdel((void*)&rdr); return (NULL); + } rdr->redir = redir; rdr->next = NULL; ft_strlcpy(rdr->path, path, PATH_MAX); -- cgit v1.2.3