Revision 18224,
1.9 KB
checked in by ghudson, 22 years ago
(diff) |
This commit was generated by cvs2svn to compensate for changes in r18223,
which included commits to RCS files with non-trunk default branches.
|
Rev | Line | |
---|
[18223] | 1 | /* |
---|
| 2 | * Copyright (C) 1998 Red Hat Inc. |
---|
| 3 | * |
---|
| 4 | * This program is free software; you can redistribute it and/or |
---|
| 5 | * modify it under the terms of the GNU General Public License as |
---|
| 6 | * published by the Free Software Foundation; either version 2 of the |
---|
| 7 | * License, or (at your option) any later version. |
---|
| 8 | * |
---|
| 9 | * This program is distributed in the hope that it will be useful, but |
---|
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 12 | * General Public License for more details. |
---|
| 13 | * |
---|
| 14 | * You should have received a copy of the GNU General Public License |
---|
| 15 | * along with this program; if not, write to the Free Software |
---|
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
| 17 | * 02111-1307, USA. |
---|
| 18 | */ |
---|
[17208] | 19 | |
---|
[18223] | 20 | |
---|
[17208] | 21 | #ifdef HAVE_CONFIG_H |
---|
| 22 | #include "config.h" |
---|
| 23 | #endif |
---|
| 24 | |
---|
| 25 | #ifdef HAVE_ALLOCA_H |
---|
| 26 | # include <alloca.h> |
---|
| 27 | #else |
---|
| 28 | # ifdef _AIX |
---|
| 29 | # pragma alloca |
---|
| 30 | # endif |
---|
| 31 | #endif |
---|
| 32 | |
---|
| 33 | #include <stdio.h> |
---|
| 34 | #include <stdlib.h> |
---|
| 35 | #include <string.h> |
---|
| 36 | #ifdef HAVE_UNISTD_H |
---|
| 37 | #include <unistd.h> |
---|
| 38 | #endif |
---|
| 39 | #ifdef __NeXT |
---|
| 40 | /* access macros are not declared in non posix mode in unistd.h - |
---|
| 41 | don't try to use posix on NeXTstep 3.3 ! */ |
---|
| 42 | #include <libc.h> |
---|
| 43 | #endif |
---|
| 44 | |
---|
| 45 | #include "findme.h" |
---|
| 46 | |
---|
[18223] | 47 | #if !defined(X_OK) |
---|
[17208] | 48 | #define X_OK 1 |
---|
| 49 | #endif |
---|
| 50 | |
---|
| 51 | char * findProgramPath(char * argv0) { |
---|
| 52 | char * path = getenv("PATH"); |
---|
| 53 | char * pathbuf; |
---|
| 54 | char * start, * chptr; |
---|
| 55 | char * buf; |
---|
| 56 | |
---|
| 57 | /* If there is a / in the argv[0], it has to be an absolute |
---|
| 58 | path */ |
---|
| 59 | if (strchr(argv0, '/')) |
---|
| 60 | return strdup(argv0); |
---|
| 61 | |
---|
| 62 | if (!path) return NULL; |
---|
| 63 | |
---|
| 64 | start = pathbuf = alloca(strlen(path) + 1); |
---|
| 65 | buf = malloc(strlen(path) + strlen(argv0) + 2); |
---|
| 66 | strcpy(pathbuf, path); |
---|
| 67 | |
---|
| 68 | chptr = NULL; |
---|
| 69 | do { |
---|
| 70 | if ((chptr = strchr(start, ':'))) |
---|
| 71 | *chptr = '\0'; |
---|
| 72 | sprintf(buf, "%s/%s", start, argv0); |
---|
| 73 | |
---|
| 74 | if (!access(buf, X_OK)) |
---|
| 75 | return buf; |
---|
| 76 | |
---|
| 77 | if (chptr) |
---|
| 78 | start = chptr + 1; |
---|
| 79 | else |
---|
| 80 | start = NULL; |
---|
| 81 | } while (start && *start); |
---|
| 82 | |
---|
| 83 | free(buf); |
---|
| 84 | |
---|
| 85 | return NULL; |
---|
| 86 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.