-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_envp.c
More file actions
executable file
·47 lines (43 loc) · 1.54 KB
/
init_envp.c
File metadata and controls
executable file
·47 lines (43 loc) · 1.54 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init_envp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hyeyeom <hyeyeom@42student.gyeongsan.kr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/15 15:13:14 by hyeyeom #+# #+# */
/* Updated: 2025/04/14 00:38:35 by hyeyeom ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int init_copy_envp(t_minish *sh, char **envp)
{
int i;
sh->envp_count = f_count_char(envp);
sh->envp = (char **)malloc(sizeof(char *) * (sh->envp_count + 1));
if (!sh->envp)
return (-1);
i = -1;
while (++i < (sh->envp_count))
{
sh->envp[i] = ft_strdup(envp[i]);
if (!sh->envp[i])
{
while (--i >= 0)
free(sh->envp[i]);
free(sh->envp);
exit(EXIT_FAILURE);
}
}
sh->envp[sh->envp_count] = NULL;
return (0);
}
int init_envp(t_minish *sh, char **envp)
{
sh->prev_for_pipe = -1;
if (init_copy_envp(sh, envp) == -1)
return (-1);
f_init_env(sh->envp, &(sh->n_envs));
f_sort_and_store_envp(sh->envp, &(sh->n_export));
return (0);
}