diff options
author | salad <fmoenne-@student.le-101.fr> | 2020-10-26 13:42:56 +0100 |
---|---|---|
committer | salad <fmoenne-@student.le-101.fr> | 2020-10-26 13:42:56 +0100 |
commit | 0277ddfac754ab4ad5bdd2b692e31a717efbe569 (patch) | |
tree | 49d7c5fd3a12248af85e2c3a3254bc1538ae5775 /src/u_vars_next.c | |
parent | reqdy for MERGE (diff) | |
parent | TODO update (diff) | |
download | 42-minishell-0277ddfac754ab4ad5bdd2b692e31a717efbe569.tar.gz 42-minishell-0277ddfac754ab4ad5bdd2b692e31a717efbe569.tar.bz2 42-minishell-0277ddfac754ab4ad5bdd2b692e31a717efbe569.tar.xz 42-minishell-0277ddfac754ab4ad5bdd2b692e31a717efbe569.tar.zst 42-minishell-0277ddfac754ab4ad5bdd2b692e31a717efbe569.zip |
merge wif master
Diffstat (limited to '')
-rw-r--r-- | src/u_vars_next.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/u_vars_next.c b/src/u_vars_next.c index c6c351b..2f23667 100644 --- a/src/u_vars_next.c +++ b/src/u_vars_next.c @@ -13,15 +13,16 @@ #include <libft.h> #include <inttypes.h> #include <stdlib.h> +#include <limits.h> #include "d_enum.h" #include "s_lvars.h" #include "s_struct.h" +#include "u_parse.h" #include "u_utils.h" static int64_t - u_get_env_var_line(const char varname[], - t_msh *msh) + u_get_env_var_line(const char varname[], t_msh *msh) { char **env_dup; int64_t i; @@ -42,8 +43,7 @@ static int64_t } static t_bool - u_get_custom_var_existance(const char varname[], - t_msh *msh) + u_get_custom_var_existance(const char varname[], t_msh *msh) { t_lvars *ptr; @@ -63,6 +63,11 @@ static t_bool } } +/* static void */ +/* u_newval_subst(char newval_subst[], const char newval[]) */ +/* { */ +/* } */ + /* ** void ** u_subst_var_value(const char varname[], const char newval[], t_msh *msh); @@ -70,23 +75,22 @@ static t_bool ** DESCRIPTION ** The subst_var_value() changes the value of msh->envp ** variable varname[] with newval[]. If varname[] wasn't found -** in msh->envp, varname[] is searched in msh->vars. +** in msh->envp, varname[] is searched in msh->vars. Otherwise +** varname[] is added to msh->vars. */ void - u_subst_var_value(const char varname[], - const char newval[], - t_msh *msh) + u_subst_var_value(const char varname[], const char newval[], t_msh *msh) { - char new_line_fmt[2048]; + char new_line_fmt[ARG_MAX]; int64_t env_line; if ((env_line = u_get_env_var_line(varname + 1, msh)) > -1) { ft_memdel((void*)&msh->envp[env_line]); ft_sprintf(new_line_fmt, "%s=%s", varname + 1, newval); - if (!(msh->envp[env_line] = - (char*)malloc((ft_strlen(new_line_fmt) + 1) * sizeof(char)))) + if ((msh->envp[env_line] = (char*)malloc((ft_strlen(new_line_fmt) + 1) * + sizeof(char))) == NULL) { /* TODO: Handle this fail */ } |