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
)
14 char * path
= getenv("PATH");
16 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 bufsize
= strlen(path
) + 1;
28 start
= pathbuf
= alloca(bufsize
);
29 if (pathbuf
== NULL
) return NULL
; /* XXX can't happen */
30 strlcpy(pathbuf
, path
, bufsize
);
31 bufsize
+= sizeof "/" - 1 + strlen(argv0
);
32 buf
= malloc(bufsize
);
33 if (buf
== NULL
) return NULL
; /* XXX can't happen */
38 if ((chptr
= strchr(start
, ':')))
40 snprintf(buf
, bufsize
, "%s/%s", start
, argv0
);
42 if (!access(buf
, X_OK
))
49 } while (start
&& *start
);