This repository was archived by the owner on Nov 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunset_builtin.c
46 lines (43 loc) · 1.58 KB
/
unset_builtin.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* unset_builtin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <mcombeau@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/17 18:29:52 by mcombeau #+# #+# */
/* Updated: 2022/11/05 12:17:21 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/* unset_builtin:
* Removes the environment variables with the given keys
* after checking if they are valid keys.
* Does nothing if the key is not in the environment.
* Returns 0 if all args were successfully unset, or 1 if
* one or more args could not be unset.
*/
int unset_builtin(t_data *data, char **args)
{
int i;
int idx;
int ret;
ret = EXIT_SUCCESS;
i = 1;
while (args[i])
{
if (!is_valid_env_var_key(args[i]) || ft_strchr(args[i], '=') != NULL)
{
errmsg_cmd("unset", args[i], "not a valid identifier", false);
ret = EXIT_FAILURE;
}
else
{
idx = get_env_var_index(data->env, args[i]);
if (idx != -1)
remove_env_var(data, idx);
}
i++;
}
return (ret);
}