-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_builtin_env.c
57 lines (53 loc) · 1.69 KB
/
ft_builtin_env.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
47
48
49
50
51
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_builtin_env.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abenamar <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/08 01:11:01 by abenamar #+# #+# */
/* Updated: 2023/09/27 14:17:44 by abenamar ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static uint8_t ft_print_variables(t_list **env)
{
t_list *lst;
lst = *env;
while (lst)
{
if (ft_strncmp(lst->content, "?=", 2))
{
if (ft_strchr(((char *) lst->content), '='))
{
if (printf("%s\n", (char *) lst->content) < 0)
return (ft_pstderr("write error"), 0);
}
}
lst = lst->next;
}
return (1);
}
int ft_builtin_env(char *cmd, char **argv, t_list **env, uint8_t silent)
{
(void) cmd;
if (!env)
return (EXIT_FAILURE);
if (argv[1])
{
if (argv[1][0] == '-')
{
if (!silent)
ft_pstderr3("env: ", argv[1], ": invalid option");
return (125);
}
if (!silent)
ft_pstderr3("env: ", argv[1], ": invalid argument");
return (EXIT_FAILURE);
}
if (silent)
return (EXIT_SUCCESS);
if (!ft_print_variables(env))
return (EXIT_FAILURE);
return (EXIT_SUCCESS);
}