#include "search-path.h" #include #include #include #include #include #include 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; }