summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/m_minishell.c1
-rw-r--r--src/u_utils.c28
-rw-r--r--src/u_utils.h1
3 files changed, 29 insertions, 1 deletions
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 <stdlib.h>
#include <stdint.h>
+#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 <stdint.h>
uint64_t u_builtins_get_argc(const char *args[]);
+char **u_get_env_var_names(t_msh *msh);
#endif