home *** CD-ROM | disk | FTP | other *** search
- #include <unistd.h>
-
- extern char *getenv();
- extern char *strchr();
-
- static
- char *
- next_attempted_path(prefix, last_component, result)
- char *prefix;
- char *last_component;
- char *result;
- {
- char *s;
-
- s = result;
-
- while (*prefix != '\0' && *prefix != ':')
- *s++ = *prefix++;
-
- if (result != s)
- *s++ = '/';
-
- while (*last_component != '\0')
- *s++ = *last_component++;
-
- *s = '\0';
-
- return (*prefix == '\0') ? (char *)0 : prefix + 1;
- }
-
- char *
- execvpath(name)
- char *name;
- {
- static char fname[256];
- char *cp;
-
- if (name == (char *)0 || strchr(name, '/') != (char *)0)
- return name;
-
- if ((cp = getenv("PATH")) == (char *)0)
- cp = "";
-
- while ((cp = next_attempted_path(cp, name, &fname[0])) != (char *)0)
- {
- if (access(&fname[0], X_OK) == 0)
- return &fname[0];
- }
-
- return name;
- }
-