Browse Source

fix unamed variable export

master
narnaud 3 years ago
parent
commit
5680ec97a9
  1. 18
      env.c

18
env.c

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */ /* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/16 09:41:29 by narnaud #+# #+# */ /* Created: 2022/02/16 09:41:29 by narnaud #+# #+# */
/* Updated: 2022/05/18 13:54:55 by narnaud@stude ### ########.fr */ /* Updated: 2022/05/18 15:24:19 by narnaud@stude ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -70,16 +70,26 @@ int ft_export(t_datas *datas, t_command *cmd)
char **env; char **env;
int i; int i;
int j; int j;
int ret ;
ret = 0;
if (cmd->argc < 2 && (ft_env(datas, cmd, 1), 1)) if (cmd->argc < 2 && (ft_env(datas, cmd, 1), 1))
return (0); return (ret);
j = 0; j = 0;
while (++j < cmd->argc) while (++j < cmd->argc)
{ {
if (!cmd->argv[j][0] || cmd->argv[j][0] == '=')
{
ret = 1;
continue ;
}
new = ft_split(cmd->argv[j], '='); new = ft_split(cmd->argv[j], '=');
name_len = ft_strlen(new[0]); name_len = ft_strlen(new[0]);
if (!is_valid_identifier(new[0])) if (!is_valid_identifier(new[0]))
return (0); {
ret = 1;
continue ;
}
i = 0; i = 0;
while (datas->envp[i]) while (datas->envp[i])
{ {
@ -93,7 +103,7 @@ int ft_export(t_datas *datas, t_command *cmd)
ft_free_split(new); ft_free_split(new);
datas->envp[i] = ft_strdup(cmd->argv[j]); datas->envp[i] = ft_strdup(cmd->argv[j]);
} }
return (0); return (ret);
} }
static void clean_env(t_datas *datas, int i) static void clean_env(t_datas *datas, int i)

Loading…
Cancel
Save