summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-10-22 20:34:23 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-10-22 20:34:23 +0200
commitc782926734e139eed9d45c1015bf2b0cee8e6165 (patch)
tree2bd8ccfa126bf1fa59964331ade23b9bfa355fd3
parenttwo-and-one unDONE (diff)
download42-minishell-c782926734e139eed9d45c1015bf2b0cee8e6165.tar.gz
42-minishell-c782926734e139eed9d45c1015bf2b0cee8e6165.tar.bz2
42-minishell-c782926734e139eed9d45c1015bf2b0cee8e6165.tar.xz
42-minishell-c782926734e139eed9d45c1015bf2b0cee8e6165.tar.zst
42-minishell-c782926734e139eed9d45c1015bf2b0cee8e6165.zip
Error handled
-rw-r--r--src/s_lredir.c12
1 files changed, 10 insertions, 2 deletions
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 <libft.h>
#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
#include <unistd.h>
+#include <errno.h>
#ifdef __linux__
# include <linux/limits.h>
#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);
}