summaryrefslogtreecommitdiffstats
path: root/src/p_redirs.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-28 19:34:00 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-28 19:34:00 +0200
commit4df7b992eac08144283cfc589c2a8bc6f4c136ee (patch)
tree291bbce77b0f5b609ced0108757b27b3483471da /src/p_redirs.c
parentNew libft funcs (diff)
download42-minishell-4df7b992eac08144283cfc589c2a8bc6f4c136ee.tar.gz
42-minishell-4df7b992eac08144283cfc589c2a8bc6f4c136ee.tar.bz2
42-minishell-4df7b992eac08144283cfc589c2a8bc6f4c136ee.tar.xz
42-minishell-4df7b992eac08144283cfc589c2a8bc6f4c136ee.tar.zst
42-minishell-4df7b992eac08144283cfc589c2a8bc6f4c136ee.zip
Fix redirs done
Diffstat (limited to '')
-rw-r--r--src/p_redirs.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/p_redirs.c b/src/p_redirs.c
index eeaefea..cbc9a10 100644
--- a/src/p_redirs.c
+++ b/src/p_redirs.c
@@ -43,9 +43,9 @@ static void p_append_redir(const char path[],
return ;
}
new->heredoc = NULL;
- if (redir == -2)
+ if (redir == -2 || redir == -3)
{
- new->heredoc = p_get_heredoc(path, msh);
+ new->heredoc = p_get_heredoc(path, redir, msh);
}
s_lredir_add_back(&com->rdr, new);
}
@@ -56,17 +56,17 @@ static size_t p_get_path(char path[],
{
char h[PATH_MAX];
size_t pos[2];
- size_t len[2];
+ size_t hlen;
+ size_t len;
- len[1] = 0;
+ hlen = 0;
tmp.ptr += ft_abs(tmp.redir);
- tmp.ptr += (tmp.redir == -2 && *tmp.ptr == '-') ? (1) : (0);
while (*tmp.ptr != C_NUL && ft_iswhitespace(*tmp.ptr) == TRUE)
tmp.ptr++;
if (*tmp.ptr == C_TILDE && u_get_var_value(h, "$HOME", PATH_MAX, msh) == 0)
{
ft_strlcpy(path, h, PATH_MAX);
- len[1] = ft_strlen(h);
+ hlen = ft_strlen(h);
tmp.ptr++;
}
pos[0] = (tmp.ptr - tmp.word);
@@ -74,9 +74,9 @@ static size_t p_get_path(char path[],
&& u_is_not_escaped(tmp.word, tmp.ptr) == TRUE)
tmp.ptr++;
pos[1] = (tmp.ptr - tmp.word);
- len[0] = (pos[1] - pos[0]);
- len[0] = ((len[1] + len[0] + 1) > PATH_MAX) ? (PATH_MAX - 1) : (len[0]);
- ft_strlcpy(path + len[1], tmp.word + pos[0], len[0] + 1);
+ len = (pos[1] - pos[0]);
+ len = ((hlen + len + 1) > PATH_MAX) ? (PATH_MAX - 1) : (len);
+ ft_strlcpy(path + hlen, tmp.word + pos[0], len + 1);
return (pos[1]);
}
@@ -116,6 +116,7 @@ static void p_get_redir(char word[], char *ptr, t_com *com, t_msh *msh)
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]);
+ fd_rdr[RDR] = (fd_rdr[RDR] == -2 && *(ptr + 2) == '-') ? (-3) : (fd_rdr[1]);
if (fd_rdr[FD] == STDOUT_FILENO)
pos[0] = (ptr - word);
else