diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-11 15:05:31 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-11 15:05:31 +0200 |
commit | 6f756ee6112c723cfe0f8ece2d530b249aa47e00 (patch) | |
tree | d855b1f53369b382c6cb204a3241561e48d99e5d | |
parent | LOT to fix (diff) | |
download | 42-minishell-6f756ee6112c723cfe0f8ece2d530b249aa47e00.tar.gz 42-minishell-6f756ee6112c723cfe0f8ece2d530b249aa47e00.tar.bz2 42-minishell-6f756ee6112c723cfe0f8ece2d530b249aa47e00.tar.xz 42-minishell-6f756ee6112c723cfe0f8ece2d530b249aa47e00.tar.zst 42-minishell-6f756ee6112c723cfe0f8ece2d530b249aa47e00.zip |
Fix
-rw-r--r-- | src/m_prompt.c | 14 | ||||
-rw-r--r-- | src/p_lblock_next.c | 4 | ||||
-rw-r--r-- | src/s_com.c | 4 |
3 files changed, 14 insertions, 8 deletions
diff --git a/src/m_prompt.c b/src/m_prompt.c index ff491c8..584a98d 100644 --- a/src/m_prompt.c +++ b/src/m_prompt.c @@ -34,14 +34,20 @@ static char { if (var[i + 1] == '0' && var[i + 2] == '3' && var[i + 3] == '3') { - (void)ft_memmove(var + i, var + i + 3, ft_strlen(var + i + 3) + 1); + (void)ft_memmove(var + i, var + (i + 3), (ft_strlen(var + (i + 3)) + 1) * sizeof(char)); var[i] = C_ESC; } else if (var[i + 1] == 'n') { - (void)ft_memmove(var + i, var + i + 1, ft_strlen(var + i + 1) + 1); + (void)ft_memmove(var + i, var + (i + 1), (ft_strlen(var + (i + 1)) + 1) * sizeof(char)); var[i] = C_LF; } + else if (var[i + 1] == 'h' || var[i + 1] == 'H') + { + gethostname(tmp, 255); + (void)ft_memmove(var + i + ft_strlen(tmp), var + (i + 2), (ft_strlen(var + (i + 2)) + 1) * sizeof(char)); + (void)ft_memcpy(var + i, tmp, ft_strlen(tmp) * sizeof(char)); + } else if (var[i + 1] == 'w') { u_get_var_value(tmp, "$PWD", PATH_MAX, msh); @@ -82,11 +88,11 @@ static char static void m_update_psx(uint8_t x, t_msh *msh) { - char var[2048]; + char var[ARG_MAX]; char psx[5]; ft_sprintf(psx, "$PS%hhu", x); - u_get_var_value(var, psx, 2048, msh); + u_get_var_value(var, psx, ARG_MAX, msh); if (var[0] == C_NUL) { msh->ps[x - 1][0] = '\0'; diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 21cd4a7..e342f4a 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -61,7 +61,7 @@ static char ft_strlcpy(tmp, ptr + i, varlen + 1 - i); u_get_var_value(varval, tmp, ARG_MAX, msh); p_double_them_bs(varval); - ft_strlcpy(tmp, ptr + varlen, varlen); + ft_strlcpy(tmp, ptr + varlen, varlen + 1); if ((word = ft_nrealloc(word, i, i + ft_strlen(varval) + ft_strlen(tmp) + 1)) == NULL) return (NULL); @@ -150,9 +150,9 @@ static char int64_t i, t_msh *msh) { + char **rewords; int64_t j; int64_t k; - char **rewords; j = 0; if (reg == TRUE) diff --git a/src/s_com.c b/src/s_com.c index 95f2d94..ee55c58 100644 --- a/src/s_com.c +++ b/src/s_com.c @@ -96,8 +96,7 @@ void } t_com - *s_com_new(char word[], - t_msh *msh) + *s_com_new(char word[], t_msh *msh) { t_com *com; char **words; @@ -114,6 +113,7 @@ t_com return (NULL); if ((word = p_subst_vars(word, msh)) == NULL) return (NULL); + msh->curr->lblock = word; if ((words = p_split_args(word, com->redir)) == NULL) return (NULL); if ((words = p_subst_home(words, msh)) == NULL) |