summaryrefslogtreecommitdiffstats
path: root/src/s_lredir.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-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);