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
) { /* XXX can't happen */
34 strcpy(pathbuf
, path
);
39 if ((chptr
= strchr(start
, ':')))
41 sprintf(buf
, "%s/%s", start
, argv0
);
43 if (!access(buf
, X_OK
)) {
52 } while (start
&& *start
);