diff options
Diffstat (limited to 'stdlib/header.c')
-rw-r--r-- | stdlib/header.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/stdlib/header.c b/stdlib/header.c index d1a3bffac..1fb0bfbf3 100644 --- a/stdlib/header.c +++ b/stdlib/header.c @@ -29,7 +29,9 @@ char * default_runtime_path = RUNTIME_NAME; +#ifndef MAXPATHLEN #define MAXPATHLEN 1024 +#endif #ifndef S_ISREG #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) @@ -39,6 +41,10 @@ char * default_runtime_path = RUNTIME_NAME; #define SEEK_END 2 #endif +#ifndef __CYGWIN32__ + +/* Normal Unix search path function */ + static char * searchpath(char * name) { static char fullname[MAXPATHLEN + 1]; @@ -67,6 +73,55 @@ static char * searchpath(char * name) return fullname; } +#else + +/* Special version for Cygwin32: takes care of the ".exe" implicit suffix */ + +static int file_ok(char * name) +{ + int fd; + /* Cannot use stat() here because it adds ".exe" implicitly */ + fd = open(name, O_RDONLY); + if (fd == -1) return 0; + close(fd); + return 1; +} + +static char * searchpath(char * name) +{ + char * path, * fullname, * p; + + path = getenv("PATH"); + fullname = malloc(strlen(name) + (path == NULL ? 0 : strlen(path)) + 6); + /* 6 = "/" plus ".exe" plus final "\0" */ + if (fullname == NULL) return name; + /* Check for absolute path name */ + for (p = name; *p != 0; p++) { + if (*p == '/' || *p == '\\') { + if (file_ok(name)) return name; + strcpy(fullname, name); + strcat(fullname, ".exe"); + if (file_ok(fullname)) return fullname; + return name; + } + } + /* Search in path */ + if (path == NULL) return name; + while(1) { + for (p = fullname; *path != 0 && *path != ':'; p++, path++) *p = *path; + if (p != fullname) *p++ = '/'; + strcpy(p, name); + if (file_ok(fullname)) return fullname; + strcat(fullname, ".exe"); + if (file_ok(fullname)) return fullname; + if (*path == 0) break; + path++; + } + return name; +} + +#endif + static unsigned long read_size(char * ptr) { unsigned char * p = (unsigned char *) ptr; @@ -122,6 +177,7 @@ int main(int argc, char ** argv) errwrite(" not found or is not a bytecode executable file\n"); return 2; } + argv[0] = truename; execv(runtime_path, argv); errwrite("Cannot exec "); errwrite(runtime_path); |