summaryrefslogtreecommitdiffstats
path: root/src/p_redirs.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-27 19:53:11 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-27 19:53:11 +0200
commita656c8155406b698d4eb02b2fe1ec662338fec58 (patch)
tree0c50d61e699394d1c81062238c2f829ac27d62b1 /src/p_redirs.c
parent<<EOF in progress (diff)
download42-minishell-a656c8155406b698d4eb02b2fe1ec662338fec58.tar.gz
42-minishell-a656c8155406b698d4eb02b2fe1ec662338fec58.tar.bz2
42-minishell-a656c8155406b698d4eb02b2fe1ec662338fec58.tar.xz
42-minishell-a656c8155406b698d4eb02b2fe1ec662338fec58.tar.zst
42-minishell-a656c8155406b698d4eb02b2fe1ec662338fec58.zip
Progress
Diffstat (limited to 'src/p_redirs.c')
-rw-r--r--src/p_redirs.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/p_redirs.c b/src/p_redirs.c
index c978212..7c71d13 100644
--- a/src/p_redirs.c
+++ b/src/p_redirs.c
@@ -26,9 +26,9 @@
#include "u_vars.h"
static void p_append_redir(const char path[],
- int32_t fd,
- int8_t redir,
- t_com *com)
+ int32_t fd_rdr[],
+ t_com *com,
+ t_msh *msh)
{
struct s_lredir *new;
@@ -101,16 +101,15 @@ static void p_get_redir(char word[], char *ptr, t_com *com, t_msh *msh)
struct s_rdr_tmp tmp;
char path[PATH_MAX];
size_t pos[2];
- int32_t fd;
- int8_t redir;
+ int32_t fd_rdr[2];
pos[0] = 0;
- if ((fd = p_get_fd(word, ptr)) <= 0)
- fd = STDOUT_FILENO;
- redir = (*ptr == '>') ? (1) : (-1);
- redir = (redir == 1 && *(ptr + 1) == '>') ? (2) : (redir);
- redir = (redir == -1 && *(ptr + 1) == '<') ? (-2) : (redir);
- if (fd == STDOUT_FILENO)
+ if ((fd_rdr[FD] = p_get_fd(word, ptr)) <= 0)
+ fd_rdr[FD] = STDOUT_FILENO;
+ fd_rdr[RDR] = (*ptr == '>') ? (1) : (-1);
+ fd_rdr[RDR] = (fd_rdr[RDR] == 1 && *(ptr + 1) == '>') ? (2) : (fd_rdr[1]);
+ fd_rdr[RDR] = (fd_rdr[RDR] == -1 && *(ptr + 1) == '<') ? (-2) : (fd_rdr[1]);
+ if (fd_rdr[FD] == STDOUT_FILENO)
pos[0] = (ptr - word);
else
pos[0] = (ptr - word) - ft_intlen(fd);
@@ -120,7 +119,7 @@ static void p_get_redir(char word[], char *ptr, t_com *com, t_msh *msh)
pos[1] = p_get_path(path, tmp, msh);
(void)ft_memmove(word + pos[0],
word + pos[1], (ft_strlen(word + pos[1]) + 1) * sizeof(char));
- p_append_redir(path, fd, redir, com);
+ p_append_redir(path, fd_rdr, redir, com);
}
int8_t p_redirs(char word[], t_com **com, t_msh *msh)