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
| | #include "search-path.h"
#include <stdlib.h>
#include <talloc.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 *c = NULL, *save = NULL, *tok;
size_t n;
int dfd = -1;
notmuch_bool_t ret = FALSE;
if (strchr(exename, '/')) {
if (0 == access(exename, X_OK))
return TRUE;
else
return FALSE;
}
c = getenv("PATH");
if (c)
c = talloc_strdup(NULL, c);
else {
n = confstr(_CS_PATH, NULL, 0);
c = (char*)talloc_size(NULL, n);
if (!c)
return FALSE;
confstr(_CS_PATH, c, n);
}
tok = strtok_r(c, ":", &save);
while (tok) {
dfd = open(tok, O_DIRECTORY | O_RDONLY);
if (dfd != -1) {
if (!faccessat(dfd, exename, X_OK, 0)) {
ret = TRUE;
goto done;
}
close(dfd);
}
tok = strtok_r(NULL, ":", &save);
}
done:
if (dfd != -1)
close(dfd);
if (c)
talloc_free(c);
return ret;
}
|