-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities_cont.c
93 lines (83 loc) · 2.04 KB
/
utilities_cont.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
90
91
92
93
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utilities_cont.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kblack <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/27 13:16:27 by kblack #+# #+# */
/* Updated: 2019/03/28 21:29:04 by kblack ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/*
** Check the name of the current user
*/
int check_user(char *name, t_shell *sh)
{
t_env *tmp;
tmp = sh->env_info;
while (tmp)
{
if (ft_strcmp(tmp->key, "USER") == 0)
{
if (ft_strcmp(tmp->value, name) == 0)
return (0);
}
tmp = tmp->next;
}
return (-1);
}
void check_error(char *p, char *arg)
{
int i;
int slash;
i = -1;
slash = 0;
while (arg[++i])
{
if (arg[i] == '/')
slash++;
}
if (slash > 0 && !p)
ft_printf("ash: no such file or directory: %s\n", arg);
else if (!p)
ft_printf("ash: command not found: %s\n", arg);
}
void tilda_handler(char *arg, t_shell *sh)
{
char *user;
int tmp;
user = NULL;
tmp = 0;
if (arg[1])
{
user = ft_strsub(arg, 1, ft_strlen(arg) - 1);
tmp = check_user(user, sh);
if (tmp < 0)
{
ft_printf("cd: permission denied: /nfs/2018/%c/%s\n", arg[1], user);
free(user);
return ;
}
}
free(user);
find_env("HOME", get_value(sh, "PWD"), sh);
}
int ft_this_list_size(t_env *begin_list)
{
t_env *current;
int i;
i = 0;
current = begin_list;
if (current)
{
while (current->next)
{
current = current->next;
i++;
}
i++;
}
return (i);
}