|
|
@ -6,7 +6,7 @@ |
|
|
|
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */ |
|
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
|
/* 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) |
|
|
|