-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcopy_env.c
49 lines (44 loc) · 1.43 KB
/
copy_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
/* ************************************************************************** */
/* */
/* :::::::: */
/* copy_env.c :+: :+: */
/* +:+ */
/* By: sde-rijk <[email protected]> +#+ */
/* +#+ */
/* Created: 2021/12/27 13:35:53 by sde-rijk #+# #+# */
/* Updated: 2022/01/24 13:58:33 by dnoom ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "Libft/libft.h"
#include <stdio.h>
void copy_env(char **envp, t_env *s_env)
{
int i;
i = 0;
while (envp[i])
i++;
s_env->env = ft_calloc((i + 1) * sizeof(char *), 1);
s_env->size = i;
i = 0;
while (envp[i])
{
s_env->env[i] = ft_strdup(envp[i]);
i++;
}
s_env->term_out = dup(STDOUT_FILENO);
s_env->term_in = dup(STDIN_FILENO);
if (s_env->term_out < 0 || s_env->term_in < 0)
perror("dup");
}
void ft_free_env(t_env *s_env)
{
int i;
i = 0;
while (s_env->env[i])
{
free(s_env->env[i]);
i++;
}
free(s_env->env);
}