aboutsummaryrefslogtreecommitdiff
path: root/src/env_to_strlst.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/env_to_strlst.c')
-rw-r--r--src/env_to_strlst.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/env_to_strlst.c b/src/env_to_strlst.c
new file mode 100644
index 0000000..c4c98c3
--- /dev/null
+++ b/src/env_to_strlst.c
@@ -0,0 +1,58 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* env_to_strlst.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/12/17 19:22:28 by chuhlig #+# #+# */
+/* Updated: 2024/12/17 19:22:36 by chuhlig ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+#include "minishell.h"
+
+static char *get_var_assign(t_env *cur);
+
+char **env_to_strlst(t_env *env)
+{
+ int size;
+ t_env *cur;
+ char **result;
+ int i;
+
+ size = 0;
+ cur = env;
+ while (cur != NULL)
+ {
+ size++;
+ cur = cur->next;
+ }
+ result = malloc(sizeof(char *) * (size + 1));
+ if (result == NULL)
+ return (NULL);
+ i = 0;
+ cur = env;
+ while (i < size)
+ {
+ result[i] = get_var_assign(cur);
+ cur = cur->next;
+ i++;
+ }
+ result[i] = NULL;
+ return (result);
+}
+
+static char *get_var_assign(t_env *cur)
+{
+ char *left_side;
+ char *result;
+
+ left_side = ft_strjoin(cur->name, "=");
+ if (left_side == NULL)
+ return (NULL);
+ result = ft_strjoin(left_side, cur->value);
+ free(left_side);
+ return (result);
+} \ No newline at end of file