blob: ce33121ab4d856735c45a5305cf615b75ca923b8 (
plain)
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
|
/* find the path to a file by name */
static char *which(const char *fname)
{
static char fullpath[BUFSIZ];
char *ret, *path, *p;
ret = NULL;
path = getenv("PATH");
if (!path)
return ret;
path = xstrdup(path);
while ((p = strrchr(path, ':')) != NULL) {
snprintf(fullpath, sizeof(fullpath), "%s/%s", p + 1, fname);
*p = 0;
if (access(fullpath, R_OK) != -1) {
ret = fullpath;
break;
}
}
free(path);
return ret;
}
|