blob: 9d0c66f31a69bc3f1c831b88fb9dddbef5fba4ac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:10:51 by charles #+# #+# */
/* Updated: 2020/09/13 20:22:35 by charles ### ########.fr */
/* */
/* ************************************************************************** */
/*
** \file unset.c
** \brief `unset` builtin
*/
#include "minishell.h"
/*
** \brief Remove variables from the environment
** \param argv arguments
** \param env environment
** \return a status code or EVAL_FATAL on fatal error
*/
int builtin_unset(char **argv, t_env env)
{
size_t i;
int found_index;
int status;
status = 0;
i = 0;
while (argv[++i] != NULL)
{
if (!utils_valid_identifier(argv[i]))
{
errorf("unset: `%s': not a valid identifier\n", argv[i]);
status = 1;
continue ;
}
found_index = env_search_index(env, argv[i]);
if (found_index == -1)
continue ;
ft_vecremove(env, found_index, free);
}
return (status);
}
|