-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipex.fun.c
More file actions
76 lines (69 loc) · 1.89 KB
/
pipex.fun.c
File metadata and controls
76 lines (69 loc) · 1.89 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex.fun.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sakllam <sakllam@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/05 20:30:59 by sakllam #+# #+# */
/* Updated: 2021/12/07 11:51:59 by sakllam ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
int ft_opticheckcmd(t_commands **cmd, char *cmdline)
{
*cmd = malloc(sizeof(t_commands));
if (!(*cmd))
return (1);
(*cmd)->cmd = ft_split(cmdline, ' ');
if (!(*cmd)->cmd)
return (1);
return (0);
}
t_commands *ft_check_for_cmd(char *cmdline, char **path)
{
t_commands *cmd;
int i;
if (ft_opticheckcmd(&cmd, cmdline))
return (NULL);
i = -1;
while (path[++i])
{
cmd->pathcmd = ft_strjoinbeta(path[i], cmd->cmd[0]);
if (!cmd->pathcmd)
return (NULL);
if (!access(cmd->pathcmd, X_OK))
break ;
free(cmd->pathcmd);
}
cmd->next = NULL;
if (!path[i])
return (NULL);
return (cmd);
}
char **ft_get_executable_foulders(char **en)
{
int i;
char **result;
char *adrs;
i = -1;
while (en[++i])
{
if (!ft_strncmp(en[i], "PATH=", 5))
break ;
}
if (ft_strncmp(en[i], "PATH=", 5))
return (NULL);
adrs = &en[i][5];
result = ft_split(adrs, ':');
return (result);
}
void ft_baliseexit(t_all_data *stock)
{
stock->count = 0;
if (stock->fd_file1 < 1)
{
perror("FILE:");
exit(1);
}
}