aboutsummaryrefslogtreecommitdiff
path: root/src/env_to_strlst.c
diff options
context:
space:
mode:
authorChristopher Uhlig2025-01-13 11:06:54 +0100
committerChristopher Uhlig2025-01-13 11:06:54 +0100
commit78dc50a2bce3c6e31405437189e2990d8fc720ac (patch)
treed61d9f0d279e191c1bfb34929908f412cf58c02d /src/env_to_strlst.c
parentae5512ea0d6d8be833ca3a9b39f93239109f45b4 (diff)
downloadminishell-78dc50a2bce3c6e31405437189e2990d8fc720ac.tar.gz
minishell-78dc50a2bce3c6e31405437189e2990d8fc720ac.zip
here
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