summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-28 18:57:09 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-28 18:57:09 +0200
commit2d75e800a1cd3dff630ec0080a864ef1779496c9 (patch)
treefa1ffe1d148a0cb731d8622c635963dd450fd084 /src
parentTODO.org update (diff)
download42-minishell-2d75e800a1cd3dff630ec0080a864ef1779496c9.tar.gz
42-minishell-2d75e800a1cd3dff630ec0080a864ef1779496c9.tar.bz2
42-minishell-2d75e800a1cd3dff630ec0080a864ef1779496c9.tar.xz
42-minishell-2d75e800a1cd3dff630ec0080a864ef1779496c9.tar.zst
42-minishell-2d75e800a1cd3dff630ec0080a864ef1779496c9.zip
New libft funcs
Diffstat (limited to 'src')
-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]);
}