From ac11eee947958d539eed289dbb7c52d9ffd790be Mon Sep 17 00:00:00 2001 From: hugogogo Date: Thu, 25 Nov 2021 21:33:46 +0100 Subject: [PATCH] unset ok --- README.md | 1 + srcs/builtins/unset.c | 24 +++++++++--------------- srcs/init.c | 4 ++-- srcs/main.c | 4 ++-- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 2520083..3acb1a5 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ - init.c - minishell_structs.h - export.c +- subshell_exec.c ## TESTS SIGNAUX WITH HERE-DOCS : diff --git a/srcs/builtins/unset.c b/srcs/builtins/unset.c index 57a8150..2db1c14 100644 --- a/srcs/builtins/unset.c +++ b/srcs/builtins/unset.c @@ -3,27 +3,21 @@ int builtin_unset(int argc, char *argv[], t_all *c) { - int position; extern char **environ; + int env_position; (void)argc; (void)c; - //position = getenv_position(c->envp, argv[1]); - position = getenv_position(environ, argv[1]); - if (position == -1) + env_position = getenv_position(environ, argv[1]); + if (environ[env_position] == '\0') return (0); -// while (c->envp[position]) - while (environ[position]) + while (environ[env_position + 1]) { -write(1, "1", 1); - //free(c->envp[position]); - free(environ[position]); - //c->envp[position] = ft_strdup(c->envp[position + 1]); - environ[position] = ft_strdup(environ[position + 1]); - position++; + free(environ[env_position]); + environ[env_position] = ft_strdup(environ[env_position + 1]); + env_position++; } -write(1, "2", 1); - //free(c->envp[position]); - free(environ[position]); + free(environ[env_position]); + environ[env_position] = NULL; return (0); } diff --git a/srcs/init.c b/srcs/init.c index 1d423ac..cf93a56 100644 --- a/srcs/init.c +++ b/srcs/init.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */ -/* Updated: 2021/11/25 18:57:59 by hulamy ### ########.fr */ +/* Updated: 2021/11/25 19:47:00 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,7 @@ int init(t_all *c, char **environ) // if (!c->envp) // return (ft_reti_perror(0, "ft_dup_2d_char_arr(envp) error")); //print_matrix(c->envp, "\n --- \n"); // TEST WIP - //c->path = retrieve_path(c->envp); // No return check. Its intended. PATH is optional +// c->path = retrieve_path(c->envp); // No return check. Its intended. PATH is optional c->path = retrieve_path(environ); // No return check. Its intended. PATH is optional c->prompt_base = init_prompt_base(); if (!c->prompt_base) diff --git a/srcs/main.c b/srcs/main.c index 93519dc..67f752c 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */ -/* Updated: 2021/11/25 16:30:24 by hulamy ### ########.fr */ +/* Updated: 2021/11/25 19:48:07 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ int main(int argc, char *argv[]) (void)argc; (void)argv; - //if (!init(&c, envp)) +// if (!init(&c, envp)) if (!init(&c, environ)) free_exit(&c, EXIT_FAILURE); //putenv("VAR=W1 W2 W3"); // TEMP TEST