| 1 |
from main.c |
| 2 |
#else |
| 3 |
kcl_self = find_executable(argv[0]); |
| 4 |
#endif |
| 5 |
|
| 6 |
|
| 7 |
#ifdef NeXT |
| 8 |
#include <fcntl.h> |
| 9 |
#include <sys/stat.h> |
| 10 |
|
| 11 |
|
| 12 |
static int |
| 13 |
is_executable(fn) |
| 14 |
char *fn; |
| 15 |
{ |
| 16 |
struct stat s; |
| 17 |
|
| 18 |
return stat (fn, &s) != -1 && (s.st_mode & S_IFMT) == S_IFREG |
| 19 |
&& access (fn, X_OK) != -1; |
| 20 |
} |
| 21 |
|
| 22 |
char * |
| 23 |
find_executable(fn) |
| 24 |
char *fn; |
| 25 |
{ |
| 26 |
char *path, *getenv(); |
| 27 |
static char buf[MAXPATHLEN+1]; |
| 28 |
static char msg[100]; |
| 29 |
register char *p; |
| 30 |
|
| 31 |
for (p = fn; *p; p++) { |
| 32 |
if (*p == '/') { |
| 33 |
if (is_executable (fn)) |
| 34 |
return fn; |
| 35 |
else { |
| 36 |
sprintf(msg, "%s is not executable", fn); |
| 37 |
error(msg); |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
if ((path = getenv ("PATH")) == 0) |
| 42 |
error("PATH is undefined"); |
| 43 |
do { |
| 44 |
p = buf; |
| 45 |
while (*path && *path != ':') |
| 46 |
*p++ = *path++; |
| 47 |
if (*path) |
| 48 |
++path; |
| 49 |
if (p > buf) |
| 50 |
*p++ = '/'; |
| 51 |
strcpy (p, fn); |
| 52 |
if (is_executable (buf)) |
| 53 |
return buf; |
| 54 |
} while (*path); |
| 55 |
sprintf(msg, "cannot find pathname of %s", fn); |
| 56 |
error(msg); |
| 57 |
} |
| 58 |
#endif |
| 59 |
|
| 60 |
|