1999-10-06 12:47:43 -04:00
|
|
|
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
|
|
|
|
file accompanying popt source distributions, available from
|
|
|
|
ftp://ftp.redhat.com/pub/code/popt */
|
|
|
|
|
2000-07-10 19:00:56 -04:00
|
|
|
#include "common.h"
|
1999-10-06 12:47:43 -04:00
|
|
|
|
|
|
|
#ifdef __NeXT
|
|
|
|
/* access macros are not declared in non posix mode in unistd.h -
|
|
|
|
don't try to use posix on NeXTstep 3.3 ! */
|
|
|
|
#include <libc.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "findme.h"
|
|
|
|
|
|
|
|
char * findProgramPath(char * argv0) {
|
|
|
|
char * path = getenv("PATH");
|
|
|
|
char * pathbuf;
|
|
|
|
char * start, * chptr;
|
|
|
|
char * buf;
|
|
|
|
|
|
|
|
/* If there is a / in the argv[0], it has to be an absolute
|
|
|
|
path */
|
|
|
|
if (strchr(argv0, '/'))
|
2000-07-10 19:00:56 -04:00
|
|
|
return g_strdup(argv0);
|
1999-10-06 12:47:43 -04:00
|
|
|
|
|
|
|
if (!path) return NULL;
|
|
|
|
|
2000-12-02 02:08:49 -05:00
|
|
|
start = pathbuf = g_strdup(path);
|
|
|
|
buf = g_malloc(strlen(path) + strlen(argv0) + 2);
|
1999-10-06 12:47:43 -04:00
|
|
|
|
|
|
|
chptr = NULL;
|
|
|
|
do {
|
|
|
|
if ((chptr = strchr(start, ':')))
|
|
|
|
*chptr = '\0';
|
|
|
|
sprintf(buf, "%s/%s", start, argv0);
|
|
|
|
|
2000-10-26 14:57:23 -04:00
|
|
|
#ifndef WIN32
|
2000-12-02 02:08:49 -05:00
|
|
|
if (!access(buf, X_OK)) {
|
|
|
|
g_free(pathbuf);
|
1999-10-06 12:47:43 -04:00
|
|
|
return buf;
|
2000-12-02 02:08:49 -05:00
|
|
|
}
|
2000-10-26 14:57:23 -04:00
|
|
|
#endif
|
1999-10-06 12:47:43 -04:00
|
|
|
|
|
|
|
if (chptr)
|
|
|
|
start = chptr + 1;
|
|
|
|
else
|
|
|
|
start = NULL;
|
|
|
|
} while (start && *start);
|
|
|
|
|
2000-12-02 02:08:49 -05:00
|
|
|
g_free(pathbuf);
|
1999-10-06 12:47:43 -04:00
|
|
|
free(buf);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|