diff --git a/built-in.c b/built-in.c index f2b38b1..039e301 100755 --- a/built-in.c +++ b/built-in.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/06 09:02:57 by narnaud #+# #+# */ -/* Updated: 2022/05/17 17:31:53 by narnaud ### ########.fr */ +/* Updated: 2022/05/18 13:45:47 by narnaud@stude ### ########.fr */ /* */ /* ************************************************************************** */ @@ -78,7 +78,7 @@ int ft_cd(t_datas *datas, t_command *cmd) { char *home; - if (cmd->argc > 1) + if (cmd->argc > 2) return (cmd_error("cd", "too many arguments")); if (cmd->argv[1]) { diff --git a/env.c b/env.c index 404cb5f..537bf4c 100755 --- a/env.c +++ b/env.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/02/16 09:41:29 by narnaud #+# #+# */ -/* Updated: 2022/05/16 10:43:01 by mea ### ########.fr */ +/* Updated: 2022/05/18 13:54:55 by narnaud@stude ### ########.fr */ /* */ /* ************************************************************************** */ @@ -69,26 +69,31 @@ int ft_export(t_datas *datas, t_command *cmd) int name_len; char **env; int i; + int j; - i = 0; if (cmd->argc < 2 && (ft_env(datas, cmd, 1), 1)) return (0); - new = ft_split(cmd->argv[1], '='); - name_len = ft_strlen(new[0]); - if (!is_valid_identifier(new[0])) - return (0); - while (datas->envp[i]) + j = 0; + while (++j < cmd->argc) { - env = ft_split(datas->envp[i], '='); - if (!ft_strncmp(new[0], env[0], name_len + 1)) - datas->envp[i] = (free(datas->envp[i]), NULL); - else - i++; - ft_free_split(env); + new = ft_split(cmd->argv[j], '='); + name_len = ft_strlen(new[0]); + if (!is_valid_identifier(new[0])) + return (0); + i = 0; + while (datas->envp[i]) + { + env = ft_split(datas->envp[i], '='); + if (!ft_strncmp(new[0], env[0], name_len + 1)) + datas->envp[i] = (free(datas->envp[i]), NULL); + else + i++; + ft_free_split(env); + } + ft_free_split(new); + datas->envp[i] = ft_strdup(cmd->argv[j]); } - ft_free_split(new); - datas->envp[i] = ft_strdup(cmd->argv[1]); - return (1); + return (0); } static void clean_env(t_datas *datas, int i)