1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
12 /* check if path points to an executable file;
16 int execable_file(const char *name)
19 return (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode));
22 /* search $PATH for an executable file;
23 * return allocated string containing full path if found;
24 * return NULL otherwise;
26 char *find_execable(const char *filename)
30 p = path = xstrdup(getenv("PATH"));
35 if (*p != '\0') { /* it's not a PATH="foo::bar" situation */
36 p = concat_path_file(p, filename);
37 if (execable_file(p)) {
49 /* search $PATH for an executable file;
53 int exists_execable(const char *filename)
55 char *ret = find_execable(filename);