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.
9 alloca replaced with malloc()/free() pair */
14 const char * findProgramPath(const char * argv0) {
15 char * path = getenv("PATH");
17 char * start, * chptr;
20 if (argv0 == NULL) return NULL; /* XXX can't happen */
21 /* If there is a / in the argv[0], it has to be an absolute path */
22 if (strchr(argv0, '/'))
23 return xstrdup(argv0);
25 if (path == NULL) return NULL;
27 start = pathbuf = malloc(strlen(path) + 1);
28 if (pathbuf == NULL) return NULL;
29 buf = malloc(strlen(path) + strlen(argv0) + sizeof("/"));
30 if (buf == NULL) return NULL; /* XXX can't happen */
31 strcpy(pathbuf, path);
36 if ((chptr = strchr(start, ':')))
38 sprintf(buf, "%s/%s", start, argv0);
40 if (!access(buf, X_OK)) {
49 } while (start && *start);