summaryrefslogtreecommitdiffstats
path: root/src/p_redirs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/p_redirs.c')
-rw-r--r--src/p_redirs.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/p_redirs.c b/src/p_redirs.c
index b615d01..eeaefea 100644
--- a/src/p_redirs.c
+++ b/src/p_redirs.c
@@ -56,28 +56,27 @@ static size_t p_get_path(char path[],
{
char h[PATH_MAX];
size_t pos[2];
- size_t hlen;
- size_t len;
+ size_t len[2];
- hlen = 0;
- tmp.redir = (tmp.redir < 0) ? (-tmp.redir) : (tmp.redir);
- tmp.ptr += tmp.redir;
+ len[1] = 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);
- hlen = ft_strlen(h);
+ len[1] = ft_strlen(h);
tmp.ptr++;
}
pos[0] = (tmp.ptr - tmp.word);
- while (*tmp.ptr != C_NUL && ft_iswhitespace(*tmp.ptr) == FALSE &&
- u_is_not_escaped(tmp.word, tmp.ptr) == TRUE)
+ while (*tmp.ptr != C_NUL && ft_iswhitespace(*tmp.ptr) == FALSE
+ && u_is_not_escaped(tmp.word, tmp.ptr) == TRUE)
tmp.ptr++;
pos[1] = (tmp.ptr - tmp.word);
- 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);
+ 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);
return (pos[1]);
}