summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/p_redirs.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/p_redirs.c b/src/p_redirs.c
index 86aca27..c12201e 100644
--- a/src/p_redirs.c
+++ b/src/p_redirs.c
@@ -90,8 +90,8 @@ static int32_t p_get_fd(const char word[], char *ptr)
char digit[255];
char *tmp;
- if (*ptr == '<' || (ptr - word) == 1)
- return (0);
+ if (*ptr == '<' || (ptr - word) == 0)
+ return (-1);
tmp = ptr;
tmp -= 1;
if (ft_isdigit(*tmp) == FALSE)
@@ -100,6 +100,8 @@ static int32_t p_get_fd(const char word[], char *ptr)
tmp--;
if ((tmp - word) > 0 && ft_iswhitespace(*tmp) == FALSE)
return (0);
+ if (ft_atoi(tmp) == 1 || ft_atoi(tmp) == 0)
+ return (-2);
else
{
tmp += ((tmp - word) > 0) ? (1) : (0);
@@ -116,7 +118,7 @@ static uint8_t p_get_redir(char word[], char *ptr, t_com *com, t_msh *msh)
int32_t fd_rdr[2];
pos[0] = 0;
- if ((fd_rdr[FD] = p_get_fd(word, ptr)) <= 0)
+ if ((fd_rdr[FD] = p_get_fd(word, ptr)) == -1)
fd_rdr[FD] = STDOUT_FILENO;
fd_rdr[RDR] = (*ptr == '>') ? (1) : (-1);
fd_rdr[RDR] = (fd_rdr[RDR] == 1 && *(ptr + 1) == '>') ? (2) : (fd_rdr[1]);
@@ -125,6 +127,8 @@ static uint8_t p_get_redir(char word[], char *ptr, t_com *com, t_msh *msh)
fd_rdr[RDR] = (fd_rdr[RDR] == -2 && *(ptr + 2) == '-') ? (-3) : (fd_rdr[1]);
pos[0] = (fd_rdr[FD] == STDOUT_FILENO) ?
(ptr - word) : ((ptr - word) - ft_intlen(fd_rdr[FD]));
+ pos[0] = (fd_rdr[FD] == -2) ? ((ptr - word) - 1) : (pos[0]);
+ fd_rdr[FD] = (fd_rdr[FD] == -2) ? (STDOUT_FILENO) : (fd_rdr[FD]);
tmp.word = word;
tmp.ptr = ptr;
tmp.redir = fd_rdr[RDR];