-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_paths.c
69 lines (67 loc) · 1.42 KB
/
search_paths.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
58
59
60
61
62
63
64
65
66
67
68
69
#include "shell.h"
/**
<<<<<<< HEAD
* search_paths - locate a directory path with the command
* @token_path : directory path
* @command : command
*
* Return: command found ; 1 otherwise
=======
* search_paths - search a directory path listing the command
* @path_list : list of path directories
* @command : shorthand command to search
*
* Return: 0 if successful; 1 otherwise
>>>>>>> nick
*/
int search_paths(char **path_list, char *command)
{
int i = 0;
<<<<<<< HEAD
if ((realpath(command, (char *)*command_dir)) == NULL)
{
perror("Realpath Error");
exit(EXIT_FAILURE);
}
while (token_path[i] != '\0')
{
open_dir = opendir(&token_path[i]);
if (open_dir == NULL)
{
perror("Opendir Error");
exit(EXIT_FAILURE);
}
*read_dir = readdir(open_dir);
if (*read_dir == NULL)
{
perror("Readdir Error");
exit(EXIT_FAILURE);
}
scan_count = scandir(&token_path[i], scan_list, NULL, (int *)
alphasort(read_dir, command_dir));
if (scan_count == -1)
{
perror("Scandir Error");
exit(EXIT_FAILURE);
}
if ((path_command = strstr((**scan_list)->d_name, command))
!= NULL)
break;
closedir(open_dir);
i++;
}
printf("%s\n", path_command);
printf("%s", PROMPT);
return (path_command);
=======
while (path_list[i++] != NULL)
{
if ((_scandir(command, path_list[i])) == EXIT_FAILURE)
{
perror("Scandir Error");
return (EXIT_FAILURE);
}
}
return (EXIT_SUCCESS);
>>>>>>> nick
}