-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnot_built_error.c
More file actions
78 lines (73 loc) · 1.93 KB
/
not_built_error.c
File metadata and controls
78 lines (73 loc) · 1.93 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
71
72
73
74
75
76
77
78
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* not_built_error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamoussa <mamoussa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/05 16:55:30 by mamoussa #+# #+# */
/* Updated: 2020/12/10 16:48:14 by mamoussa ### ########.fr */
/* */
/* ************************************************************************** */
#include "shell.h"
size_t not_built_error_helper(char **res, char *cmd)
{
g_tmp = res[0];
res[0] = (res[0][ft_strlen(res[0]) - 1] != '/') ?
ft_strjoin(res[0], "/") : res[0];
simple_pointer_free(g_tmp);
g_tmp = res[0];
res[0] = ft_strjoin(res[0], cmd);
simple_pointer_free(g_tmp);
if (open(res[0], O_RDONLY) > 0)
{
g_tmp = g_cmd_head->string;
g_cmd_head->string = ft_strdup(res[0]);
simple_pointer_free(g_tmp);
return (1);
}
return (0);
}
size_t abs_path(char *cmd, char **res)
{
if (open(cmd, O_RDONLY) < 0)
{
free(cmd);
double_pointer_free(res);
return (0);
}
else
{
free(cmd);
double_pointer_free(res);
return (1);
}
return (0);
}
size_t not_built_error(void)
{
char **res;
char *cmd;
size_t i;
i = 0;
res = path_spliter();
cmd = ft_strdup(g_cmd_head->string);
while (res[i])
{
if (check_for_slash(cmd))
return (abs_path(cmd, res));
else
{
if (not_built_error_helper(&res[i], cmd))
{
free(cmd);
double_pointer_free(res);
return (1);
}
}
i++;
}
free(cmd);
double_pointer_free(res);
return (0);
}