-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0parser.c
57 lines (52 loc) · 1.85 KB
/
0parser.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 0parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: guilmira <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/19 11:03:27 by guilmira #+# #+# */
/* Updated: 2021/12/10 09:38:24 by guilmira ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
/** PURPOSE : Check argument counter.
* This parser does not check the values of argv. */
int parser(int argc, char *argv[])
{
if (argc < ARGUMENTS)
return (0);
argv = (char **)argv;
return (1);
}
/** PURPOSE : Close fork file pointer replica not to be used. */
int prepare_process(int fd_to_close, int fd_to_prepare)
{
close(fd_to_close);
return (fd_to_prepare);
}
/** PURPOSE : Checks whether command exists and if it does,
* returns full path to it. */
char *set_path(char *command, char **folders)
{
int i;
char *command_path;
char *current_dir;
command_path = NULL;
current_dir = NULL;
i = -1;
while (folders[++i])
{
command_path = ft_strjoin(folders[i], command);
if (file_exists(command_path))
return (command_path);
free(command_path);
}
current_dir = "/Users/guilmira/Desktop/pipex/";
command_path = ft_strjoin(current_dir, command);
if (file_exists(command_path))
return (command_path);
else
free(command_path);
return (NULL);
}