Пример #1
0
int
_putenv(const char *strng)
{
	int i = 0;
	char **e;

	del_env(strng);

	if (!_environ_ptr)
	  _environ_ptr = _environ;

	{
		while(_environ_ptr[i]) i++ ;
		e = (char **) malloc((i+2)*sizeof(char *));
		if (!e) {
			return -1;
		}
		memcpy(e, _environ_ptr, (i+1)*sizeof(char *));
		free(_environ_ptr);
		_environ_ptr = e;
	}
	if (!e)
		return -1;

	_environ_ptr = e;
	_environ_ptr[i] = (char *)strng;
	_environ_ptr[i+1] = 0;
	return 0;
}
Пример #2
0
int					ft_unsetenv(t_shell *shell, t_tree *tree)
{
	t_env			*envc;
	t_env			*tmp;
	char			*args;

	envc = shell->env;
	if (envc)
	{
		args = (tree->argv)[1];
		if (args)
		{
			while (envc && envc->next && ft_strcmp(envc->name, args))
			{
				tmp = envc;
				envc = envc->next;
			}
			if (!ft_strcmp(envc->name, args))
			{
				del_env(envc, tmp, shell);
				env_delone(&envc);
				return (EXIT_SUCCESS);
			}
		}
	}
	return (EXIT_FAILURE);
}
Пример #3
0
void			ft_error(int b_exit, t_env *e, char *str)
{
	del_env(e);
	if (str)
		write(2, str, ft_strlen(str));
	if (b_exit)
	{
		write(2, "Exit.\n", 6);
		exit(1);
	}
}
Пример #4
0
int			main(int ac, char **av)
{
	t_env	*e;

	if ((e = (t_env *)ft_memalloc(sizeof(t_env))) == NULL)
		ft_error_system();
	params_parsing(ac, av, e);
	if (e->err == NULL && (e->dir == NULL && e->file == NULL))
	{
		if (e->flg->d == TRUE)
			file_lstadd(e, ".", FALSE);
		else
			dir_lstadd(&e->dir, e->flg, ".");
	}
	print_file_lst(e);
	print_dir_lst(e);
	del_env(&e);
	return (e->global_err);
}
Пример #5
0
int				bi_unsetenv(char **arg, t_duo **env)
{
	int			i;

	i = 1;
	if (!arg[i])
		ft_putendl("minishell: unsetenv: too few arguments.");
	while (arg[i])
	{
		if (del_env(env, arg[i]) == -1)
		{
			ft_putstr("minishell: unsetenv: '");
			ft_putstr(arg[i]);
			ft_putendl("': undefined variable");
		}
		i++;
	}
	return (0);
}
Пример #6
0
int					init_env(char **env, t_duo **env_cpy)
{
	char				**cpy;

	cpy = NULL;
	if (tbl_len(env) == 0)
		fill_path(&cpy);
	if (cpy)
	{
		*env_cpy = tbl_to_duo(cpy, '=');
		free_tab(&cpy);
	}
	else
		*env_cpy = tbl_to_duo(env, '=');
	if (env_cpy == NULL && *env_cpy == NULL)
		return (sh_error(FALSE, 6, NULL, NULL));
	del_env(env_cpy, "OLDPWD");
	savior_env(*env_cpy, TRUE);
	sh_lvl();
	savior_env(*env_cpy, TRUE);
	return (TRUE);
}
Пример #7
0
int		handle_env_opt(t_node_cmd *node, int *it)
{
	if (ft_strequ("-i", node->cmd[*it]) && (*it)++)
		del_env(&node->env);
	else if (ft_strequ("-P", node->cmd[*it]) && node->cmd[*it + 1])
	{
		set_env(&node->env, "PATH", ft_strdup(node->cmd[*it + 1]));
		(*it) += 2;
	}
	else if (ft_strequ("-P", node->cmd[*it]))
		return (-1);
	else if (ft_strequ("-u", node->cmd[*it]) && node->cmd[*it + 1])
	{
		unset_env(&node->env, node->cmd[*it + 1]);
		(*it) += 2;
	}
	else if (ft_strequ("-u", node->cmd[*it]))
		return (-1);
	else if (ft_strchr(node->cmd[*it], '='))
	{
		set_env_keyval(&node->env, node->cmd[(*it)++]);
	}
	return (1);
}
Пример #8
0
void wipe_env(void) {
    while(del_env());
}
Пример #9
0
int pop_env(void) {
    if(current_env_is_not_top_env())
        return del_env();
    return 1;
}