aboutsummaryrefslogtreecommitdiff
path: root/src/env_to_strlst.c
diff options
context:
space:
mode:
authorChristopher Uhlig2025-01-20 13:06:34 +0100
committerChristopher Uhlig2025-01-20 13:06:34 +0100
commit8f5abcdb257393a2e576fe382835e8e060662834 (patch)
tree1b923423b22bb59ff10ea07b0700a5a7bdf96f5a /src/env_to_strlst.c
parent3392f2b811269f174620832d663b09ef4f4e43f3 (diff)
downloadminishell-8f5abcdb257393a2e576fe382835e8e060662834.tar.gz
minishell-8f5abcdb257393a2e576fe382835e8e060662834.zip
merged
Diffstat (limited to 'src/env_to_strlst.c')
-rw-r--r--src/env_to_strlst.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/env_to_strlst.c b/src/env_to_strlst.c
index a1ab7cc..5806d96 100644
--- a/src/env_to_strlst.c
+++ b/src/env_to_strlst.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/17 19:22:28 by chuhlig #+# #+# */
-/* Updated: 2025/01/14 19:34:10 by chuhlig ### ########.fr */
+/* Updated: 2025/01/18 18:50:49 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,25 +15,32 @@
static char *get_var_assign(t_env *cur);
-char **env_to_strlst(t_env *env)
+static int getsize(t_env *env)
{
int size;
t_env *cur;
- char **result;
- int i;
size = 0;
cur = env;
- while (cur != NULL)
+ while (cur)
{
- if (ft_strchr(cur->name, '?'))
- {
- cur = cur->next;
- continue ;
- }
- size++;
+ if (!ft_strchr(cur->name, '?'))
+ size++;
cur = cur->next;
}
+ return (size);
+}
+
+char **env_to_strlst(t_env *env)
+{
+ int size;
+ t_env *cur;
+ char **result;
+ int i;
+
+ size = 0;
+ cur = env;
+ size = getsize(env);
result = malloc(sizeof(char *) * (size + 1));
if (result == NULL)
return (NULL);