Definition in file findme.c.
#include "system.h"
#include "findme.h"
Include dependency graph for findme.c:

Go to the source code of this file.
Functions | |
| const char * | findProgramPath (const char *argv0) |
| const char* findProgramPath | ( | const char * | argv0 | ) |
Return absolute path to executable by searching PATH.
| argv0 | name of executable |
Definition at line 12 of file findme.c.
References alloca(), buf, and xstrdup.
00012 { 00013 char * path = getenv("PATH"); 00014 char * pathbuf; 00015 char * start, * chptr; 00016 char * buf; 00017 00018 if (argv0 == NULL) return NULL; /* XXX can't happen */ 00019 /* If there is a / in the argv[0], it has to be an absolute path */ 00020 if (strchr(argv0, '/')) 00021 return xstrdup(argv0); 00022 00023 if (path == NULL) return NULL; 00024 00025 start = pathbuf = alloca(strlen(path) + 1); 00026 buf = malloc(strlen(path) + strlen(argv0) + sizeof("/")); 00027 if (buf == NULL) return NULL; /* XXX can't happen */ 00028 strcpy(pathbuf, path); 00029 00030 chptr = NULL; 00031 /*@-branchstate@*/ 00032 do { 00033 if ((chptr = strchr(start, ':'))) 00034 *chptr = '\0'; 00035 sprintf(buf, "%s/%s", start, argv0); 00036 00037 if (!access(buf, X_OK)) 00038 return buf; 00039 00040 if (chptr) 00041 start = chptr + 1; 00042 else 00043 start = NULL; 00044 } while (start && *start); 00045 /*@=branchstate@*/ 00046 00047 free(buf); 00048 00049 return NULL; 00050 }
Here is the call graph for this function:
