This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_2.c
57 lines (53 loc) · 1.68 KB
/
export_2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* export_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mhoyer <mhoyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/31 23:27:45 by ebouvier #+# #+# */
/* Updated: 2023/09/05 14:30:01 by mhoyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "builtin.h"
int replace_env(t_kv *env, char **tmp)
{
while (env)
{
if (is_same(env->key, tmp[0]))
{
free(env->value);
free(tmp[0]);
env->value = ft_calloc(sizeof(char), ft_strlen(tmp[1]) + 1);
if (!env->value)
return (1);
ft_strlcpy(env->value, tmp[1], ft_strlen(tmp[1]) + 1);
free(tmp[1]);
return (0);
}
env = env->next;
}
return (0);
}
int export_no_value(char **cmd, int i, t_minishell *minishell)
{
char *swap;
char **tmp;
int error;
swap = ft_strjoin(cmd[i], "=");
tmp = ft_separate(swap, '=');
if (valid_name(minishell->env, tmp[0]) == 1)
error = 0;
else if (valid_name(minishell->env, tmp[0]) == 0)
error = new_env(&minishell->env, tmp);
else
error = 2;
if (error == 2)
{
free(tmp[0]);
free(tmp[1]);
}
free(swap);
free(tmp);
return (error);
}