-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_export.c
More file actions
60 lines (55 loc) · 1.6 KB
/
ft_export.c
File metadata and controls
60 lines (55 loc) · 1.6 KB
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
58
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_export.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: makbulut <makbulut@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 20:29:01 by makbulut #+# #+# */
/* Updated: 2022/09/05 13:46:36 by makbulut ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include "minishell.h"
#include "42-Libft/libft.h"
static void set_reset(char *s)
{
char *key;
char *value;
if (!ft_strchr(s, '='))
{
ft_setenv(s, 0);
return ;
}
value = ft_get_value(s);
key = ft_get_key(s);
if (!value)
{
ft_setenv(key, "");
return ;
}
ft_setenv(key, value);
}
int ft_export(t_command *command)
{
int i;
i = 0;
if (!command->arguments[1])
ft_onlyexport(command);
else
{
while (command->arguments[++i])
{
if (ft_env_check(command->arguments[i]))
set_reset(command->arguments[i]);
else
{
ft_putstr_fd("bash: export: '", 2);
ft_putstr_fd(command->arguments[i], 2);
ft_putendl_fd("':not a valid identifier", 2);
return (1);
}
}
}
return (0);
}