示例#1
0
int				sh_setenv(t_info *info, char **env, char **args)
{
	char		name[1024];

	if (!args[0])
		sh_printenv(info, env, args);
	else if (args[1] && args[2])
		ft_putendl_fd("sh_setenv: Too many arguments.", 2);
	else if (test_alpha(args[0]))
		ft_putendl_fd("sh_setenv: Variable name must contain"
		" alphanumeric characters.", 2);
	else
	{
		ft_bzero(name, 1024);
		ft_strcpy(name, args[0]);
		ft_strcat(name, "=");
		if (args[1])
			ft_strcat(name, args[1]);
		if (ft_replaceenv(name, info->env))
			ft_addenv(name, &info->env);
	}
	return (EXIT_SUCCESS);
}
示例#2
0
void ft_setenv(t_env **env)
{
	char **split;

	if (array_size((*env)->av) > 1)
		if (ft_strchr((*env)->av[1], '=') != NULL)
		{
			split = ft_strsplit((*env)->av[1], '=');
			if (is_env(*env, split[0]) != -1)
				ft_replaceenv(&(*env), split, (*env)->av[1]);
			else
				(*env)->e = ft_arradd((*env)->e, (*env)->av[1]);
		}
		else
		{
			if (is_env(*env, split[0]) == -1)
				{
					split[0] = ft_strjoin(split[0], "=");
					(*env)->e = ft_arradd((*env)->e, split[0]);
				}		
		}
	else
		ft_putendl("Usage : setenv KEY=VALUE");
}