From 471845b565e9ce30b78c1db3d5fc34db9ec33aa6 Mon Sep 17 00:00:00 2001 From: Etienne Rey-bethbeder Date: Thu, 30 Mar 2023 13:12:18 +0200 Subject: [PATCH] =?UTF-8?q?Astuce:=20=C3=A9cout=C3=A9=20Raoult?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builtins/cd.c | 11 +++-------- builtins/export.c | 2 +- env/env1.c | 6 ++++-- env/env3.c | 6 +++++- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/builtins/cd.c b/builtins/cd.c index 5ef897d..336b3ea 100644 --- a/builtins/cd.c +++ b/builtins/cd.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/20 14:27:36 by erey-bet #+# #+# */ -/* Updated: 2023/03/13 15:11:07 by erey-bet ### ########.fr */ +/* Updated: 2023/03/21 13:16:24 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,17 +32,12 @@ int move_folder(char **args, int fd) { char *path; - if (args[1] != NULL) + if (args[1] != NULL || args[0] == NULL) { - write(2, "cd: too many argument\n", 22); + write(2, "cd: Wrong number's argument\n", 28); return (1); } path = args[0]; - if (!path) - { - write(2, "No such file or directory\n", 26); - return (1); - } if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0) { if (chdir(path) == 0) diff --git a/builtins/export.c b/builtins/export.c index f3ff510..b8bd135 100644 --- a/builtins/export.c +++ b/builtins/export.c @@ -6,7 +6,7 @@ /* By: cchauvet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */ -/* Updated: 2023/03/09 19:01:05 by erey-bet ### ########.fr */ +/* Updated: 2023/03/30 13:07:15 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,7 +61,9 @@ int set_value_by_key(char *key, char *value, t_list **head) if (ft_strcmp(((t_env *)current->content)->key, key) == 0) { free(((t_env *)current->content)->value); + free(((t_env *)current->content)->key); ((t_env *)current->content)->value = value; + ((t_env *)current->content)->key = key; return (0); } current = current->next; diff --git a/env/env3.c b/env/env3.c index d6b2653..5c058ab 100644 --- a/env/env3.c +++ b/env/env3.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */ -/* Updated: 2023/03/09 19:58:55 by erey-bet ### ########.fr */ +/* Updated: 2023/03/30 12:51:54 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,10 +74,14 @@ int delete_by_key(char *key, t_list **head) { if (ft_strcmp(((t_env *)current->content)->key, key) == 0) { + free(((t_env *)current->content)->key); + free(((t_env *)current->content)->value); + free(current->content); if (last->next != NULL) last->next = current->next; else *head = current->next; + free(current); return (0); } last = current;