diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-30 18:05:18 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-30 18:05:18 +0200 |
commit | 9dfe2936fe61e08c39a808105bb9f3220a6fca46 (patch) | |
tree | 57de5e400aa04161df3b98de125e0d79eb3feab1 | |
parent | Normed b_export_mute (diff) | |
download | 42-minishell-9dfe2936fe61e08c39a808105bb9f3220a6fca46.tar.gz 42-minishell-9dfe2936fe61e08c39a808105bb9f3220a6fca46.tar.bz2 42-minishell-9dfe2936fe61e08c39a808105bb9f3220a6fca46.tar.xz 42-minishell-9dfe2936fe61e08c39a808105bb9f3220a6fca46.tar.zst 42-minishell-9dfe2936fe61e08c39a808105bb9f3220a6fca46.zip |
Normed b_export_next
-rw-r--r-- | src/b_export_next.c | 28 | ||||
-rw-r--r-- | src/b_export_next.h | 14 |
2 files changed, 19 insertions, 23 deletions
diff --git a/src/b_export_next.c b/src/b_export_next.c index 1fc732e..3457f6d 100644 --- a/src/b_export_next.c +++ b/src/b_export_next.c @@ -21,8 +21,7 @@ #include "u_utils.h" #include "u_vars.h" -static char - **b_get_var(const char arg[], t_msh *msh) +static char **b_get_var(const char arg[], t_msh *msh) { size_t len; char **var; @@ -33,18 +32,17 @@ static char while (arg[len] != '=' && arg[len] != '\0') len++; len += 1; - if ((var[FT_VAR_NAME] = (char*)malloc((len + 1) * sizeof(char))) == NULL) + if ((var[B_VAR_NAME] = (char*)malloc((len + 1) * sizeof(char))) == NULL) f_alloc_and_destroy_msh(msh); - var[FT_VAR_NAME][0] = '$'; - ft_strlcpy(var[FT_VAR_NAME] + 1, arg, len); - if ((var[FT_VAR_VAL] = ft_strdup(arg + len)) == NULL) + var[B_VAR_NAME][0] = '$'; + ft_strlcpy(var[B_VAR_NAME] + 1, arg, len); + if ((var[B_VAR_VAL] = ft_strdup(arg + len)) == NULL) f_alloc_and_destroy_msh(msh); - var[FT_VAR_NULL] = NULL; + var[B_VAR_NULL] = NULL; return (var); } -static int64_t - b_is_it_in_env(const char varname[], t_msh *msh) +static int64_t b_is_it_in_env(const char varname[], t_msh *msh) { char **env_dup; size_t i; @@ -64,8 +62,7 @@ static int64_t return (-1); } -static void - b_add_to_env(const char arg[], t_msh *msh) +static void b_add_to_env(const char arg[], t_msh *msh) { size_t i; char **nenvp; @@ -89,8 +86,7 @@ static void msh->envp = nenvp; } -void - b_export_with_equals(const char arg[], t_msh *msh) +void b_export_with_equals(const char arg[], t_msh *msh) { char varval[4096]; char **var; @@ -98,18 +94,18 @@ void varval[0] = C_NUL; var = b_get_var(arg, msh); - if ((env_i = b_is_it_in_env(var[FT_VAR_NAME] + 1, msh)) != -1) + if ((env_i = b_is_it_in_env(var[B_VAR_NAME] + 1, msh)) != -1) { ft_memdel((void*)&msh->envp[env_i]); if ((msh->envp[env_i] = ft_strdup(arg)) == NULL) f_alloc_and_destroy_msh(msh); return ; } - u_get_custom_var(varval, var[FT_VAR_NAME], 4096, msh); + u_get_custom_var(varval, var[B_VAR_NAME], 4096, msh); if (varval[0] != C_NUL) { b_add_to_env(arg, msh); - lvars_delone(&msh->vars, var[FT_VAR_NAME] + 1); + lvars_delone(&msh->vars, var[B_VAR_NAME] + 1); } else { diff --git a/src/b_export_next.h b/src/b_export_next.h index c9d53ea..02729a2 100644 --- a/src/b_export_next.h +++ b/src/b_export_next.h @@ -10,16 +10,16 @@ /* */ /* ************************************************************************** */ -#ifndef B_EXPORT_NEXT_H -#define B_EXPORT_NEXT_H +#ifndef FT_B_EXPORT_NEXT_H +# define FT_B_EXPORT_NEXT_H -#include "s_struct.h" +# include "s_struct.h" -enum +enum e_var { - FT_VAR_NAME, - FT_VAR_VAL, - FT_VAR_NULL + B_VAR_NAME, + B_VAR_VAL, + B_VAR_NULL }; void b_export_with_equals(const char arg[], t_msh *msh); |