Beispiel #1
0
int			ft_delto_env(t_data *data, char *nameofvar)
{
	char	**newenv;
	int		i;
	int		len;
	int		exist;

	i = 0;
	exist = 0;
	len = ft_strlen(nameofvar);
	while (data->environ[i])
	{
		if (ft_strncmp(data->environ[i], nameofvar, len) == 0)
			exist = 1;
		i++;
	}
	if (exist == 1)
		newenv = (char **)malloc(sizeof(char*) * (i));
	else
		return (-1);
	delto_env_part2(data, nameofvar, len, &newenv);
	ft_free_env(data->environ);
	data->environ = newenv;
	data->test++;
	return (0);
}
Beispiel #2
0
void	ft_free_env(t_env *env)
{
	if (env)
	{
		ft_free_env(env->next);
		free(env->var);
		free(env->content);
		free(env);
	}
}
static void test_unexistant_var(t_test *test)
{
	char *tab[] = {"TEST1=content1", "TEST2=content2", NULL};
	t_info info;

	test->debug = 1;
	ft_init_env(&info, tab);
	env_add_var(&info, strdup("yolo"), strdup("swag"));
	env_remove_var(&info, "JHG");
	ft_free_env(info.env);
}
static void test_env_null(t_test *test)
{
	char **tab = NULL;
	t_info info;

	test->debug = 1;
	ft_init_env(&info, tab);
	env_remove_var(&info, "yolo");
	mt_assert(!info.env);
	ft_free_env(info.env);
}
static void test_simple_test_null(t_test *test)
{
	char *tab[] = {"TEST1=content1", "TEST2=content2", NULL};
	t_info info;

	test->debug = 1;
	ft_init_env(&info, tab);
	env_add_var(&info, strdup("yolo"), strdup("swag"));
	env_remove_var(&info, NULL);
	mt_assert(!info.env->next->next->next);
	ft_free_env(info.env);
}
static void test_last_var(t_test *test)
{
	char **tab = NULL;
	t_info info;

	test->debug = 1;
	ft_init_env(&info, tab);
	env_add_var(&info, strdup("yolo"), strdup("swag"));
	env_remove_var(&info, "yolo");
	mt_assert(!info.env);
	ft_free_env(info.env);
}