1 /* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
2 file accompanying popt source distributions, available from
3 ftp://ftp.redhat.com/pub/code/popt */
8 const char * findProgramPath(const char * argv0
) {
9 char * path
= getenv("PATH");
11 char * start
, * chptr
;
12 char * buf
, *local
= NULL
;
14 /* If there is a / in the argv[0], it has to be an absolute
16 if (strchr(argv0
, '/'))
17 return xstrdup(argv0
);
19 if (!path
) return NULL
;
21 local
= start
= pathbuf
= malloc(strlen(path
) + 1);
22 buf
= malloc(strlen(path
) + strlen(argv0
) + 2);
23 strcpy(pathbuf
, path
);
27 if ((chptr
= strchr(start
, ':')))
29 sprintf(buf
, "%s/%s", start
, argv0
);
31 if (!access(buf
, X_OK
)) {
32 if (local
) free(local
);
40 } while (start
&& *start
);
43 if (local
) free(local
);