summaryrefslogtreecommitdiffstats
path: root/src/s_lredir.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-10-22 19:58:27 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-10-22 19:58:27 +0200
commitf498fb6dbbeab4b2993b834a6abd41ba8c2ed316 (patch)
tree996160c574ef2efb0145fc9cf007404facf3977a /src/s_lredir.c
parentUnfinished (diff)
download42-minishell-f498fb6dbbeab4b2993b834a6abd41ba8c2ed316.tar.gz
42-minishell-f498fb6dbbeab4b2993b834a6abd41ba8c2ed316.tar.bz2
42-minishell-f498fb6dbbeab4b2993b834a6abd41ba8c2ed316.tar.xz
42-minishell-f498fb6dbbeab4b2993b834a6abd41ba8c2ed316.tar.zst
42-minishell-f498fb6dbbeab4b2993b834a6abd41ba8c2ed316.zip
On the way but norm this shit
Diffstat (limited to 'src/s_lredir.c')
-rw-r--r--src/s_lredir.c16
1 files changed, 15 insertions, 1 deletions
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 <libft.h>
#include <stdint.h>
#include <stdlib.h>
+#include <unistd.h>
#ifdef __linux__
# include <linux/limits.h>
#else
# include <limits.h>
#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);