]> git.dkaiser.de - 42/minishell.git/commitdiff
Env (#23)
authorcuhlig <113346209+cuhlig42@users.noreply.github.com>
Thu, 17 Oct 2024 13:42:11 +0000 (15:42 +0200)
committerGitHub <noreply@github.com>
Thu, 17 Oct 2024 13:42:11 +0000 (15:42 +0200)
* Add data structure and prototypes for env

* added env linked lis c file

* fixed normitte and fixed return issue

* changed prototypes in header file

---------

Co-authored-by: Dominik Kaiser <dkaiser@2-F-4.42heilbronn.de>
Co-authored-by: Christopher Uhlig <chuhlig@1-C-5.42heilbronn.de>
include/env.h
src/env.c [new file with mode: 0644]

index f3d3c7536502b842a502b122ea9d36115c0a2267..5a6533387339d930e4fc00cd87b7268d177f1435 100644 (file)
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   env.h                                              :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
+/*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/08/08 16:53:39 by dkaiser           #+#    #+#             */
-/*   Updated: 2024/09/13 16:26:16 by dkaiser          ###   ########.fr       */
+/*   Updated: 2024/10/17 15:37:32 by chuhlig          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -17,8 +17,6 @@ typedef struct s_env
        struct s_env    *next;
 }                                      t_env;
 
-char                           *env_get(t_env *env, char *name);
-void                           env_export(t_env *env, char *name, char *value);
-void                           env_unset(t_env *env, char *name);
-char                           **env_to_strlst(t_env *env);
-t_env                          **env_from_strlst(char **lst);
+void   getenvlst(t_env **env, char **en);
+void   free_envlst(t_env **env);
+
diff --git a/src/env.c b/src/env.c
new file mode 100644 (file)
index 0000000..8105bf4
--- /dev/null
+++ b/src/env.c
@@ -0,0 +1,50 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   env.c                                              :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/10/17 14:31:07 by chuhlig           #+#    #+#             */
+/*   Updated: 2024/10/17 15:18:44 by chuhlig          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "env.h"
+
+void   getenvlst(t_env **env, char **en)
+{
+       char    *tmp;
+       int             i;
+       t_env   *current;
+
+       i = 0;
+       while (en[i] != NULL)
+       {
+               tmp = ft_strchr(en[i], '=');
+               tmp = '\0';
+               current = *env;
+               current = malloc(sizeof(t_env));
+               current->name = ft_strdup(en[i]);
+               current->value = ft_strdup(tmp + 1);
+               current->next = *env;
+               *env = current;
+               i++;
+       }
+}
+
+void   free_envlst(t_env **env)
+{
+       t_env   *cur;
+       t_env   *new;
+
+       cur = *env;
+       while (cur)
+       {
+               new = cur->next;
+               free(cur->name);
+               free(cur->value);
+               free(cur);
+               cur = new;
+       }
+}
\ No newline at end of file