diff options
Diffstat (limited to '')
-rw-r--r-- | src/m_prompt.c | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/src/m_prompt.c b/src/m_prompt.c index 1ea8d70..d0269e4 100644 --- a/src/m_prompt.c +++ b/src/m_prompt.c @@ -13,6 +13,7 @@ #include <libft.h> #include <stdint.h> #include <unistd.h> +#include <limits.h> #include "d_define.h" #include "m_prompt.h" @@ -20,12 +21,11 @@ #include "u_vars.h" static char - *m_subst_prompt_rice(char var[], - t_msh *msh) + *m_subst_prompt_rice(char var[], t_msh *msh) { + char tmp[PATH_MAX]; size_t i; size_t j; - char *tmp; i = 0; while (var[i] != '\0') @@ -34,19 +34,16 @@ static char { if (var[i + 1] == 'w') { - tmp = u_get_var_value("$PWD", msh); - if (tmp != NULL) - { + u_get_var_value(tmp, "$PWD", PATH_MAX, msh); + if (tmp[0] != C_NUL) var = ft_strsubst(var, "\\w", tmp); - ft_memdel((void*)&tmp); - } else var = ft_strsubst(var, "\\w", "?"); } else if (var[i + 1] == 'W') { - tmp = u_get_var_value("$PWD", msh); - if (tmp != NULL) + u_get_var_value(tmp, "$PWD", PATH_MAX, msh); + if (tmp[0] != C_NUL) { j = ft_strlen(tmp); if (j > 1) @@ -58,7 +55,6 @@ static char ((ft_strlen(tmp) - j) + 1) * sizeof(char)); } var = ft_strsubst(var, "\\W", tmp); - ft_memdel((void*)&tmp); } else var = ft_strsubst(var, "\\w", "?"); @@ -74,26 +70,24 @@ static char } static void - m_update_psx(uint8_t x, - t_msh *msh) + m_update_psx(uint8_t x, t_msh *msh) { - char *var; + char var[2048]; char psx[5]; ft_sprintf(psx, "$PS%hhu", x); - if ((var = u_get_var_value(psx, msh)) == NULL) + u_get_var_value(var, psx, 2048, msh); + if (var[0] == C_NUL) { msh->ps[x - 1][0] = '\0'; return ; } - var = m_subst_prompt_rice(var, msh); + m_subst_prompt_rice(var, msh); ft_strlcpy(msh->ps[x - 1], var, ft_strlen(var) + 1); - ft_memdel((void*)&var); } void - m_prompt_psx(uint8_t x, - t_msh *msh) + m_prompt_psx(uint8_t x, t_msh *msh) { m_update_psx(x, msh); ft_dprintf(STDERR_FILENO, "%s", msh->ps[x - 1]); |