-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_cd_helper.c
More file actions
56 lines (52 loc) · 1.63 KB
/
ft_cd_helper.c
File metadata and controls
56 lines (52 loc) · 1.63 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cd_helper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamoussa <mamoussa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/22 17:02:57 by mamoussa #+# #+# */
/* Updated: 2020/12/10 12:18:18 by mamoussa ### ########.fr */
/* */
/* ************************************************************************** */
#include "shell.h"
size_t cd_helper(void)
{
if (!ft_strncmp(g_cmd_head->string, "cd/", ft_strlen("cd/")))
{
chdir(g_cmd_head->string);
ft_error(strerror(errno));
write(1, ":", 1);
write(1, g_cmd_head->string, ft_strlen(g_cmd_head->string));
write(1, "\n", 1);
g_status = 127;
return (1);
}
return (0);
}
size_t ft_cd_helper(void)
{
char *str;
if (cd_helper())
return (1);
if (!ft_strncmp("cd", g_cmd_head->string,
ft_strlen(g_cmd_head->string)))
{
g_cmd_head = g_cmd_head->next;
if (!g_cmd_head)
{
str = check_for_home();
chdir(str);
return (1);
}
}
else
{
ft_error("command not found:");
write(1, g_cmd_head->string, ft_strlen(g_cmd_head->string));
write(1, "\n", 1);
g_status = 127;
return (1);
}
return (0);
}