-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhich_command.c
More file actions
58 lines (54 loc) · 1.16 KB
/
which_command.c
File metadata and controls
58 lines (54 loc) · 1.16 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
#include "shell.h"
/**
* which_command - locate a command in path
<<<<<<< HEAD
* @command : command string
*
* Return: command found ; 1 otherwise
=======
* @command : shorthand command string to search in path
*
* Return: 0 if successful; 1 otherwise
>>>>>>> nick
*/
int which_command(char *command)
{
char **path_loc = NULL;
<<<<<<< HEAD
char *found_command = NULL;
char *token_path = NULL;
char *delim = ":=";
char *path_env = "PATH";
if ((*path_loc = getenv(path_env)) == NULL)
{
perror("Get PATH Error");
exit(EXIT_FAILURE);
}
while ((token_path = strtok(*path_loc++, delim)) != NULL)
{
found_command = search_paths(token_path, command);
}
printf("%s\n", found_command);
printf("%s", PROMPT);
return (found_command);
=======
char **token_paths = NULL;
char *delim = ":=";
char *path_env = "PATH";
*path_loc = getenv(path_env);
if (*path_loc == NULL)
{
perror("Get PATH Error");
return (EXIT_FAILURE);
}
while ((*token_paths = strtok(*path_loc++, delim)) != NULL)
{
if ((search_paths(token_paths, command)) == EXIT_FAILURE)
{
perror("Search Paths Error");
return (EXIT_FAILURE);
}
}
return (EXIT_SUCCESS);
>>>>>>> nick
}