diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-30 18:28:46 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-30 18:28:46 +0200 |
commit | d0918fbad984b9ce2cb71e74fffee0a75e9c9533 (patch) | |
tree | ce746ea4206c2e1383467b9b1dff52cead740271 /src/b_unset.c | |
parent | Makefile update (diff) | |
download | 42-minishell-d0918fbad984b9ce2cb71e74fffee0a75e9c9533.tar.gz 42-minishell-d0918fbad984b9ce2cb71e74fffee0a75e9c9533.tar.bz2 42-minishell-d0918fbad984b9ce2cb71e74fffee0a75e9c9533.tar.xz 42-minishell-d0918fbad984b9ce2cb71e74fffee0a75e9c9533.tar.zst 42-minishell-d0918fbad984b9ce2cb71e74fffee0a75e9c9533.zip |
Normed b_unset
Diffstat (limited to 'src/b_unset.c')
-rw-r--r-- | src/b_unset.c | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/b_unset.c b/src/b_unset.c index d5e7b1b..7e32540 100644 --- a/src/b_unset.c +++ b/src/b_unset.c @@ -48,16 +48,14 @@ static t_bool check_valid_identifier(const char arg[]) static void b_realloc_env(size_t skip, t_msh *msh) { char **nenvp; - int8_t skipped; size_t i; i = 0; while (msh->envp[i] != NULL) i++; - if (!(nenvp = (char**)malloc(i * sizeof(char*)))) + if ((nenvp = (char**)malloc(i * sizeof(char*))) == NULL) f_alloc_and_destroy_msh(msh); i = 0; - skipped = 0; while (msh->envp[i] != NULL) { if (i == skip) @@ -65,13 +63,12 @@ static void b_realloc_env(size_t skip, t_msh *msh) i += 1; if (msh->envp[i] == NULL) break ; - skipped = 1; } - if (!(nenvp[i - skipped] = ft_strdup(msh->envp[i]))) + if ((nenvp[i - (i > skip)] = ft_strdup(msh->envp[i])) == NULL) f_alloc_and_destroy_msh(msh); i++; } - nenvp[i - 1] = 0; + nenvp[i - 1] = NULL; ft_delwords(msh->envp); msh->envp = nenvp; } @@ -97,18 +94,9 @@ static t_bool b_removed_from_env(const char arg[], t_msh *msh) return (FALSE); } -static void b_remove_it(const char arg[], t_msh *msh) -{ - if (b_removed_from_env(arg, msh) == FALSE) - { - lvars_delone(&msh->vars, arg); - } -} - uint8_t b_unset(char *args[], t_msh *msh) { char **ptr; - t_bool next; int8_t r; if (args[0] == NULL) @@ -117,16 +105,16 @@ uint8_t b_unset(char *args[], t_msh *msh) ptr = args; while (*ptr != NULL) { - next = FALSE; if (check_valid_identifier(*ptr) == FALSE) { f_fail_identifier("unset", *ptr); - next = TRUE; r = 1; + ptr++; + continue ; } - if (next == FALSE) + if (b_removed_from_env(*ptr, msh) == FALSE) { - b_remove_it(*ptr, msh); + lvars_delone(&msh->vars, *ptr); } ptr++; } |