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
| | #include "search-path.h"
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
notmuch_bool_t
test_for_executable (const char *exename)
{
char *path = NULL, *save = NULL, *tok;
notmuch_bool_t ret = FALSE;
if (strchr (exename, '/')) {
if (0 == access (exename, X_OK))
return TRUE;
else
return FALSE;
}
path = getenv ("PATH");
if (path)
path = strdup (path);
else {
size_t n = confstr (_CS_PATH, NULL, 0);
path = (char *) malloc (n);
if (! path)
return FALSE;
confstr (_CS_PATH, path, n);
}
tok = strtok_r (path, ":", &save);
while (tok) {
int dir_fd = open (tok, O_DIRECTORY | O_RDONLY);
if (dir_fd != -1) {
int access = faccessat (dir_fd, exename, X_OK, 0);
close (dir_fd);
if (access == 0) {
ret = TRUE;
break;
}
}
tok = strtok_r (NULL, ":", &save);
}
if (path)
free (path);
return ret;
}
|