summaryrefslogtreecommitdiffstats
path: root/src/u_utils.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-05 21:15:42 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-05 21:15:42 +0200
commit342c5868aad61936dcbe6ca05dc1ef7e08f0e082 (patch)
tree0f001b5aace8e20428113698750ef905df6105be /src/u_utils.c
parentQuick fix (diff)
download42-minishell-342c5868aad61936dcbe6ca05dc1ef7e08f0e082.tar.gz
42-minishell-342c5868aad61936dcbe6ca05dc1ef7e08f0e082.tar.bz2
42-minishell-342c5868aad61936dcbe6ca05dc1ef7e08f0e082.tar.xz
42-minishell-342c5868aad61936dcbe6ca05dc1ef7e08f0e082.tar.zst
42-minishell-342c5868aad61936dcbe6ca05dc1ef7e08f0e082.zip
New utils functions
Diffstat (limited to '')
-rw-r--r--src/u_utils.c28
1 files changed, 28 insertions, 0 deletions
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[])
{