-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.c
More file actions
42 lines (33 loc) · 680 Bytes
/
path.c
File metadata and controls
42 lines (33 loc) · 680 Bytes
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
#include "shell.h"
#define SIZE 100
/**
* find_file_in_path - search for executable files.
* @filename: name to be searched.
* Return: 0
*/
int find_file_in_path(const char *filename)
{
char *total;
struct stat st;
char fullPath[SIZE];
char *totalPath = getenv("PATH");
size_t len;
total = strtok(totalPath, ":");
do {
my_strcpy(fullPath, total);
my_strcat(fullPath, "/");
my_strcat(fullPath, filename);
len = my_strlen(fullPath);
if (stat(fullPath, &st) == 0)
{
write(1, " ", 1);
write(1, fullPath, len);
write(1, " found\n", 7);
return (0);
}
} while ((total = strtok(NULL, ":")));
write(1, " ", 1);
write(1, fullPath, len);
write(1, " Not found\n", 11);
return (0);
}