aboutsummaryrefslogtreecommitdiff
path: root/src/env.c
diff options
context:
space:
mode:
authorDominik Kaiser2025-01-14 16:40:30 +0100
committerGitHub2025-01-14 16:40:30 +0100
commit398b0d39cbbe2cdabbfae00f799181a37754d5c1 (patch)
tree397ae613dd39a35a6c91e7e30426f86ade4e24bb /src/env.c
parent00ad7429f223c85e99da6ffa8f7dade0c73c97b5 (diff)
parent553204e584dd08987902c7693e47744192e6bd85 (diff)
downloadminishell-398b0d39cbbe2cdabbfae00f799181a37754d5c1.tar.gz
minishell-398b0d39cbbe2cdabbfae00f799181a37754d5c1.zip
Merge branch 'main' into echo-builtint
Diffstat (limited to 'src/env.c')
-rw-r--r--src/env.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/env.c b/src/env.c
new file mode 100644
index 0000000..3110965
--- /dev/null
+++ b/src/env.c
@@ -0,0 +1,64 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* env.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/10/17 14:31:07 by chuhlig #+# #+# */
+/* Updated: 2024/10/25 19:17:54 by chuhlig ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "env.h"
+#include "get_next_line.h"
+#include "libft.h"
+#include <stdlib.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;
+ }
+}
+
+char *env_get(t_env *env, char *name)
+{
+ while (env != NULL)
+ {
+ if (!ft_strncmp(env->name, name, ft_strlen(name)))
+ return (env->value);
+ env = env->next;
+ }
+ return (NULL);
+}