-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
70 lines (63 loc) · 1.71 KB
/
main.c
File metadata and controls
70 lines (63 loc) · 1.71 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
61
62
63
64
65
66
67
68
69
70
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mtacnet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/18 10:54:29 by mtacnet #+# #+# */
/* Updated: 2017/08/30 12:07:00 by mtacnet ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static char **set_env(void)
{
t_elem *lst;
char *tmp;
char *tmp1;
char **tab;
tmp = getcwd(NULL, 0);
tmp1 = ft_strjoin("PWD=", tmp);
tab = NULL;
lst = new_list();
push_elem(&lst, tmp1);
push_elem(&lst, "SHLVL=1");
push_elem(&lst, "_=/usr/bin/env");
ft_strdel(&tmp);
ft_strdel(&tmp1);
tab = list_to_tab(&lst);
return (tab);
}
static char **cpy_env(char **environ)
{
int i;
char **tab;
i = 0;
tab = NULL;
while (environ[i] != '\0')
i++;
if (!(tab = ft_memalloc(sizeof(*tab) * (i + 1))))
exit(EXIT_FAILURE);
i = 0;
while (environ[i] != '\0')
{
tab[i] = environ[i];
i++;
}
return (tab);
}
int main(void)
{
extern char **environ;
char **env;
env = NULL;
if (environ)
{
if (environ[0] == NULL)
env = set_env();
else
env = cpy_env(environ);
}
get_line(env);
return (0);
}