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 */
7 #include "poptalloca.h"
15 /* access macros are not declared in non posix mode in unistd.h -
16 don't try to use posix on NeXTstep 3.3 ! */
22 const char * findProgramPath(const char * argv0
) {
23 char * path
= getenv("PATH");
25 char * start
, * chptr
;
28 /* If there is a / in the argv[0], it has to be an absolute
30 if (strchr(argv0
, '/'))
33 if (!path
) return NULL
;
35 start
= pathbuf
= alloca(strlen(path
) + 1);
36 buf
= malloc(strlen(path
) + strlen(argv0
) + 2);
37 strcpy(pathbuf
, path
);
41 if ((chptr
= strchr(start
, ':')))
43 sprintf(buf
, "%s/%s", start
, argv0
);
45 if (!access(buf
, X_OK
))
52 } while (start
&& *start
);