summaryrefslogtreecommitdiffstats
path: root/src/p_redirs.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/p_redirs.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/p_redirs.c b/src/p_redirs.c
index cf4cf1d..d83ebfd 100644
--- a/src/p_redirs.c
+++ b/src/p_redirs.c
@@ -22,6 +22,7 @@
#include "s_lredir.h"
#include "u_utils.h"
#include "u_parse.h"
+#include "u_vars.h"
static void p_append_redir(const char path[],
int32_t fd,
@@ -44,25 +45,32 @@ static size_t p_get_path(char path[],
const char word[],
int8_t redir)
{
+ char home[PATH_MAX];
size_t pos[2];
- size_t end;
+ size_t hlen;
+ size_t len;
- pos[0] = 0;
- pos[1] = 0;
+ hlen = 0;
redir = (redir < 0) ? (-redir) : (redir);
ptr += redir;
while (*ptr != C_NUL && ft_iswhitespace(*ptr) == TRUE)
ptr++;
+ if (*ptr == C_TILDE && u_get_var_value(home, "$HOME", PATH_MAX, msh) == 0)
+ {
+ ft_strlcpy(path, home, PATH_MAX);
+ hlen = ft_strlen(home);
+ ptr++;
+ }
pos[0] = (ptr - word);
while (*ptr != C_NUL &&
ft_iswhitespace(*ptr) == FALSE &&
u_is_not_escaped(word, ptr) == TRUE)
ptr++;
pos[1] = (ptr - word);
- end = pos[1];
- while (pos[1] - pos[0] > PATH_MAX)
- end--;
- ft_strlcpy(path, word + pos[0], end);
+ len = (pos[1] - pos[0]);
+ len = ((hlen + len + 1) > PATH_MAX) ? (PATH_MAX - 1) : (len);
+ ft_strlcpy(path + hlen, word + pos[0], len + 1);
+ ft_printf("%s\n", path);
return (pos[1]);
}
@@ -91,10 +99,10 @@ static int32_t p_get_fd(const char word[], char *ptr)
static int8_t p_get_redir(char word[], char *ptr, t_com *com)
{
- char path[PATH_MAX];
- size_t pos[2];
- int32_t fd;
- int8_t redir;
+ char path[PATH_MAX];
+ size_t pos[2];
+ int32_t fd;
+ int8_t redir;
pos[0] = 0;
pos[1] = 0;