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 */
6 * \brief Source: findProgramPath function
11 #include "poptalloca.h"
19 /* access macros are not declared in non posix mode in unistd.h -
20 don't try to use posix on NeXTstep 3.3 ! */
26 const char * findProgramPath(const char * argv0
) {
27 char * path
= getenv("PATH");
29 char * start
, * chptr
;
32 /* If there is a / in the argv[0], it has to be an absolute
34 if (strchr(argv0
, '/'))
37 if (!path
) return NULL
;
39 start
= pathbuf
= alloca(strlen(path
) + 1);
40 buf
= malloc(strlen(path
) + strlen(argv0
) + 2);
41 strcpy(pathbuf
, path
);
45 if ((chptr
= strchr(start
, ':')))
47 sprintf(buf
, "%s/%s", start
, argv0
);
49 if (!access(buf
, X_OK
))
56 } while (start
&& *start
);