diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-27 19:35:24 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-27 19:35:24 +0100 |
commit | a9ef1aa60df1b18c9541880c6779d9c2fe9ed651 (patch) | |
tree | 1ac4f099c27dfd65ca2ef4bbe906f709f377f0c4 | |
parent | Fix but more to do (diff) | |
download | 42-minishell-a9ef1aa60df1b18c9541880c6779d9c2fe9ed651.tar.gz 42-minishell-a9ef1aa60df1b18c9541880c6779d9c2fe9ed651.tar.bz2 42-minishell-a9ef1aa60df1b18c9541880c6779d9c2fe9ed651.tar.xz 42-minishell-a9ef1aa60df1b18c9541880c6779d9c2fe9ed651.tar.zst 42-minishell-a9ef1aa60df1b18c9541880c6779d9c2fe9ed651.zip |
FIX
-rw-r--r-- | src/p_redirs.c | 10 |
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]; |