Main Page   Modules   Compound List   File List   Compound Members   File Members   Related Pages  

popt/findme.c

Go to the documentation of this file.
00001 
00005 /* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING
00006    file accompanying popt source distributions, available from 
00007    ftp://ftp.rpm.org/pub/rpm/dist. */
00008 
00009 #include "system.h"
00010 #include "findme.h"
00011 
00012 const char * findProgramPath(const char * argv0) {
00013     char * path = getenv("PATH");
00014     char * pathbuf;
00015     char * start, * chptr;
00016     char * buf;
00017 
00018     /* If there is a / in the argv[0], it has to be an absolute path */
00019     if (strchr(argv0, '/'))
00020         return xstrdup(argv0);
00021 
00022     if (!path) return NULL;
00023 
00024     start = pathbuf = alloca(strlen(path) + 1);
00025     buf = malloc(strlen(path) + strlen(argv0) + sizeof("/"));
00026     strcpy(pathbuf, path);
00027 
00028     chptr = NULL;
00029     do {
00030         if ((chptr = strchr(start, ':')))
00031             *chptr = '\0';
00032         sprintf(buf, "%s/%s", start, argv0);
00033 
00034         if (!access(buf, X_OK))
00035             return buf;
00036 
00037         if (chptr) 
00038             start = chptr + 1;
00039         else
00040             start = NULL;
00041     } while (start && *start);
00042 
00043     free(buf);
00044 
00045     return NULL;
00046 }

Generated at Sun Apr 8 18:43:01 2001 for rpm by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000