diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-26 19:37:37 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-26 19:37:37 +0200 |
commit | e29c1e07a7badb655145d04ca8f9a468b796b67c (patch) | |
tree | ae1ec8547079cbee80dc969193c5dcd072ea23a4 | |
parent | TODO update (diff) | |
download | 42-minishell-e29c1e07a7badb655145d04ca8f9a468b796b67c.tar.gz 42-minishell-e29c1e07a7badb655145d04ca8f9a468b796b67c.tar.bz2 42-minishell-e29c1e07a7badb655145d04ca8f9a468b796b67c.tar.xz 42-minishell-e29c1e07a7badb655145d04ca8f9a468b796b67c.tar.zst 42-minishell-e29c1e07a7badb655145d04ca8f9a468b796b67c.zip |
In progress
-rw-r--r-- | src/d_define.h | 1 | ||||
-rw-r--r-- | src/e_redirs.c | 1 | ||||
-rw-r--r-- | src/p_redirs.c | 30 |
3 files changed, 20 insertions, 12 deletions
diff --git a/src/d_define.h b/src/d_define.h index fb387b3..65d4567 100644 --- a/src/d_define.h +++ b/src/d_define.h @@ -80,6 +80,7 @@ #define C_EQUALS 0x3d #define C_BACKS 0x5c #define C_PIPE 0x7c +#define C_TILDE 0x7e /* ** ====== FILES ====== diff --git a/src/e_redirs.c b/src/e_redirs.c index 474e043..7416349 100644 --- a/src/e_redirs.c +++ b/src/e_redirs.c @@ -67,7 +67,6 @@ void e_dup_redirs(const t_com *com, t_msh *msh) ptr = com->rdr; while (ptr != NULL) { - ft_printf("PATH: [%s]; FD: [%d]; RDR: [%hhd]\n", ptr->path, ptr->fd, ptr->redir); if (ptr->redir == -1) { e_redir_minus_one(ptr, msh); 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; |