5 /* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
6 file accompanying popt source distributions, available from
7 ftp://ftp.rpm.org/pub/rpm/dist. */
12 const char * findProgramPath(const char * argv0) {
13 char * path = getenv("PATH");
15 char * start, * chptr;
18 if (argv0 == NULL) return NULL; /* XXX can't happen */
19 /* If there is a / in the argv[0], it has to be an absolute path */
20 if (strchr(argv0, '/'))
21 return xstrdup(argv0);
23 if (path == NULL) return NULL;
25 start = pathbuf = (char *)alloca(strlen(path) + 1);
26 buf = (char *)malloc(strlen(path) + strlen(argv0) + sizeof("/"));
27 if (buf == NULL) return NULL; /* XXX can't happen */
28 strcpy(pathbuf, path);
33 if ((chptr = strchr(start, ':')))
35 sprintf(buf, "%s/%s", start, argv0);
37 if (!access(buf, X_OK))
44 } while (start && *start);