From 342c5868aad61936dcbe6ca05dc1ef7e08f0e082 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 5 Aug 2020 21:15:42 +0200 Subject: New utils functions --- src/m_minishell.c | 1 - src/u_utils.c | 28 ++++++++++++++++++++++++++++ src/u_utils.h | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/m_minishell.c b/src/m_minishell.c index dd47ac3..e88207b 100644 --- a/src/m_minishell.c +++ b/src/m_minishell.c @@ -21,7 +21,6 @@ #include "s_struct.h" #include "s_init.h" #include "s_destroy.h" -#include "s_lvars.h" int main(int argc, diff --git a/src/u_utils.c b/src/u_utils.c index 20c5cfc..a485fb3 100644 --- a/src/u_utils.c +++ b/src/u_utils.c @@ -14,6 +14,34 @@ #include #include +#include "f_fail.h" +#include "s_struct.h" + +char + **u_get_env_var_names(t_msh *msh) +{ + size_t i; + char **vars; + + i = 0; + while (msh->envp[i] != NULL) + i++; + if ((vars = (char**)malloc((i + 1) * sizeof(char*))) == NULL) + f_fail_alloc_and_destroy(msh); + i = 0; + while (msh->envp[i] != NULL) + { + if ((vars[i] = + (char*)malloc((ft_strclen(msh->envp[i], '=') + 1) + * sizeof(char))) == NULL) + f_fail_alloc_and_destroy(msh); + ft_strlcpy(vars[i], msh->envp[i], ft_strclen(msh->envp[i], '=') + 1); + i++; + } + vars[i] = NULL; + return (vars); +} + uint64_t u_builtins_get_argc(const char *args[]) { diff --git a/src/u_utils.h b/src/u_utils.h index d822343..d0cf323 100644 --- a/src/u_utils.h +++ b/src/u_utils.h @@ -16,5 +16,6 @@ #include uint64_t u_builtins_get_argc(const char *args[]); +char **u_get_env_var_names(t_msh *msh); #endif -- cgit v1.2.3