From c782926734e139eed9d45c1015bf2b0cee8e6165 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 22 Oct 2020 20:34:23 +0200 Subject: Error handled --- src/s_lredir.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/s_lredir.c b/src/s_lredir.c index b2e94e8..59ed6e1 100644 --- a/src/s_lredir.c +++ b/src/s_lredir.c @@ -13,7 +13,10 @@ #include #include #include +#include +#include #include +#include #ifdef __linux__ # include #else @@ -66,7 +69,7 @@ void s_lredir_clear(struct s_lredir **lredir) *lredir = NULL; } -static int32_t s_get_right_fd(const char path[]) +static int32_t s_get_right_fd(const char path[]) { char *ptr; int32_t rfd; @@ -79,7 +82,12 @@ static int32_t s_get_right_fd(const char path[]) ft_dprintf(STDERR_FILENO, "minishell: %s: ambigous redirect\n", path); return (-1); } - rfd = 0; + rfd = ft_atoi(path); + if (fcntl(rfd, F_GETFD) == -1) + { + ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", path, strerror(errno)); + return (-1); + } return (rfd); } -- cgit v1.2.3