From 46bf5f3463ddab66dc82d6d1a0fd53a855783edf Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 24 Apr 2008 05:15:13 +0000 Subject: * dln.c (dln_find_1): prior files with extensions to files sans extensions. [ruby-core:16517] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- dln.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'dln.c') diff --git a/dln.c b/dln.c index f3d6bf936..33b912d38 100644 --- a/dln.c +++ b/dln.c @@ -1694,26 +1694,9 @@ dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking } memcpy(bp, fname, i + 1); -#ifndef __MACOS__ - if (stat(fbuf, &st) == 0) { - if (exe_flag == 0) return fbuf; - /* looking for executable */ - if (!S_ISDIR(st.st_mode) && eaccess(fbuf, X_OK) == 0) - return fbuf; - } -#else - if (mac_fullpath = _macruby_exist_file_in_libdir_as_posix_name(fbuf)) { - if (exe_flag == 0) return mac_fullpath; - /* looking for executable */ - if (stat(mac_fullpath, &st) == 0) { - if (!S_ISDIR(st.st_mode) && eaccess(mac_fullpath, X_OK) == 0) - return mac_fullpath; - } - } -#endif #if defined(DOSISH) if (exe_flag) { - static const char *const extension[] = { + static const char extension[][5] = { #if defined(MSDOS) ".com", ".exe", ".bat", #if defined(DJGPP) @@ -1726,11 +1709,10 @@ dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking ".r", ".R", ".x", ".X", ".bat", ".BAT", /* __human68k__ */ #endif - (char *) NULL }; int j; - for (j = 0; extension[j]; j++) { + for (j = 0; j < sizeof(extension) / sizeof(extension[0]); j++) { if (fspace < strlen(extension[j])) { fprintf(stderr, "openpath: pathname too long (ignored)\n"); fprintf(stderr, "\tDirectory \"%.*s\"\n", (int) (bp - fbuf), fbuf); @@ -1747,9 +1729,28 @@ dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking #endif } + goto next; } #endif /* MSDOS or _WIN32 or __human68k__ or __EMX__ */ +#ifndef __MACOS__ + if (stat(fbuf, &st) == 0) { + if (exe_flag == 0) return fbuf; + /* looking for executable */ + if (!S_ISDIR(st.st_mode) && eaccess(fbuf, X_OK) == 0) + return fbuf; + } +#else + if (mac_fullpath = _macruby_exist_file_in_libdir_as_posix_name(fbuf)) { + if (exe_flag == 0) return mac_fullpath; + /* looking for executable */ + if (stat(mac_fullpath, &st) == 0) { + if (!S_ISDIR(st.st_mode) && eaccess(mac_fullpath, X_OK) == 0) + return mac_fullpath; + } + } +#endif + next: /* if not, and no other alternatives, life is bleak */ if (*ep == '\0') { -- cgit