From 43dd7bde4a062ba1663e07adf12abc942b00be3d Mon Sep 17 00:00:00 2001 From: y-syo Date: Mon, 29 Apr 2024 13:56:16 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip(e?= =?UTF-8?q?nv=5Fcmd.c):=20working=20on=20the=20env=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/env_cmd.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/env_cmd.c diff --git a/src/env_cmd.c b/src/env_cmd.c new file mode 100644 index 0000000..f3df81f --- /dev/null +++ b/src/env_cmd.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* env_cmd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmoussou name) + + ft_strlen(env->content) + 2); + if (!exec_env[i]) + { + ft_free("a", exec_env); + return (NULL); + } + ft_strlcpy(exec_env[i], env->name, ft_strlen(env->name)); + exec_env[i][ft_strlen(env->name)] = '='; + ft_strlcpy(exec_env[i] + ft_strlen(env->name) + 1, + env->content, ft_strlen(env->content)) + env = env->next; + i++; + } + return (exec_env); +} + +char set_env(char **env, const char *name, char *content) +{ + char *new_env; + int i; + int j; + + if (!name || !name[0]) + return (0); + for (int pog = 0; env[pog]; pog++) + printf("%s\n", env[pog]); + new_env = malloc(sizeof(char) * (ft_strlen(name) + ft_strlen(content) + 2)); + if (!new_env) + return (-1); + i = 0; + while (name[i]) + { + new_env[i] = name[i]; + i++; + } + new_env[i++] = '='; + j = 0; + while (content[j]) + { + new_env[i + j] = content[j]; + j++; + } + printf("\n%s\n\n", new_env); + return (0); +}