-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathother1.c
89 lines (80 loc) · 2.2 KB
/
other1.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* other1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aulamber <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/05/18 23:34:53 by aulamber #+# #+# */
/* Updated: 2014/05/18 23:35:12 by aulamber ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/libft.h"
#include "minishell1.h"
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
t_list *list_add_end(t_list *list, t_list *newl)
{
t_list *tmp;
tmp = list;
if (!list)
return (newl);
while (list && list->next)
list = list->next;
list->next = newl;
newl->prev = list;
return (tmp);
}
t_list *ft_list_new(char *key, char *value)
{
t_list *tmp;
tmp = ft_walloc(sizeof(t_list));
tmp->key = ft_strdup(key);
tmp->value = ft_strdup(value);
tmp->next = NULL;
tmp->prev = NULL;
return (tmp);
}
void *ft_walloc(int size)
{
void *tmp;
if ((tmp = malloc(size)))
{
ft_bzero(tmp, size);
return (tmp);
}
else
{
ft_error("Malloc failed. Exiting.");
return (NULL);
}
}
void ft_error(char *s)
{
ft_putendl("-------------------------------");
ft_putendl("");
ft_putendl(s);
ft_putendl("");
ft_putendl("-------------------------------");
exit(-1);
}
t_list *ft_change_env(t_list *list, char **foo)
{
if (!foo[1])
{
list = ft_setenv(list, "OLDPWD", ft_getenv(list, "PWD"));
list = ft_setenv(list, "PWD", ft_getenv(list, "HOME"));
chdir((const char*)ft_getenv(list, "PWD"));
}
else if (foo[1] && !foo[2])
ft_with_one_arg(list, foo);
else if (foo[1] && foo[2])
{
ft_printf("Too many arguments.\n");
return (NULL);
}
return (list);
}