ruby-changes:12206
From: nobu <ko1@a...>
Date: Mon, 29 Jun 2009 18:56:23 +0900 (JST)
Subject: [ruby-changes:12206] Ruby:r23891 (trunk): * dln.c (dln_find_1): fix for files with dots.
nobu 2009-06-29 18:56:03 +0900 (Mon, 29 Jun 2009) New Revision: 23891 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23891 Log: * dln.c (dln_find_1): fix for files with dots. [ruby-dev:38588] Modified files: trunk/ChangeLog trunk/dln.c trunk/test/ruby/test_system.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 23890) +++ ChangeLog (revision 23891) @@ -1,3 +1,7 @@ +Mon Jun 29 18:55:55 2009 Nobuyoshi Nakada <nobu@r...> + + * dln.c (dln_find_1): fix for files with dots. [ruby-dev:38588] + Mon Jun 29 17:14:31 2009 Nobuyoshi Nakada <nobu@r...> * file.c (file_expand_path): should copy original encoding. Index: dln.c =================================================================== --- dln.c (revision 23890) +++ dln.c (revision 23891) @@ -1519,7 +1519,12 @@ struct stat st; size_t i, fspace; #ifdef DOSISH - int is_abs = 0, has_path = 0, has_ext = 0; + static const char extension[][5] = { + ".exe", ".com", ".cmd", ".bat", + }; + size_t j; + int is_abs = 0, has_path = 0; + const char *ext = 0; const char *p = fname; #endif @@ -1546,23 +1551,31 @@ switch (*p) { case '/': case '\\': has_path = 1; - has_ext = 0; + ext = 0; p++; break; case '.': - has_ext = 1; + ext = p; p++; break; default: p = CharNext(p); } } + if (ext) { + for (j = 0; STRCASECMP(ext, extension[j]); j++) { + if (j == sizeof(extension) / sizeof(extension[0])) { + ext = 0; + break; + } + } + } ep = bp = 0; if (!exe_flag) { RETURN_IF(is_abs); } else if (has_path) { - RETURN_IF(has_ext); + RETURN_IF(ext); i = p - fname; if (i + 1 > size) goto toolong; fspace = size - i - 1; @@ -1646,15 +1659,7 @@ memcpy(bp, fname, i + 1); #if defined(DOSISH) - if (exe_flag && !has_ext) { - static const char extension[][5] = { -#if defined(__EMX__) || defined(_WIN32) - ".exe", ".com", ".cmd", ".bat", -/* end of __EMX__ or _WIN32 */ -#endif - }; - size_t j; - + if (exe_flag && !ext) { needs_extension: for (j = 0; j < sizeof(extension) / sizeof(extension[0]); j++) { if (fspace < strlen(extension[j])) { Index: test/ruby/test_system.rb =================================================================== --- test/ruby/test_system.rb (revision 23890) +++ test/ruby/test_system.rb (revision 23891) @@ -60,6 +60,28 @@ File.unlink tmpfilename or `/bin/rm -f "#{tmpfilename}"` File.unlink "#{tmpfilename}.bak" or `/bin/rm -f "#{tmpfilename}.bak"` + + if /mswin|mingw/ =~ RUBY_PLATFORM + testname = '[ruby-dev:38588]' + batch = "batch_tmp.#{$$}" + tmpfilename = "#{tmpdir}/#{batch}.bat" + open(tmpfilename, "wb") {|f| f.print "\r\n"} + assert(system(tmpfilename), testname) + assert(system("#{tmpdir}/#{batch}"), testname) + assert(system(tmpfilename, "1"), testname) + assert(system("#{tmpdir}/#{batch}", "1"), testname) + begin + path = ENV["PATH"] + ENV["PATH"] = "#{tmpdir.tr(File::SEPARATOR, File::ALT_SEPARATOR)}#{File::PATH_SEPARATOR + path if path}" + assert(system("#{batch}.bat"), testname) + assert(system(batch), testname) + assert(system("#{batch}.bat", "1"), testname) + assert(system(batch, "1"), testname) + ensure + ENV["PATH"] = path + end + File.unlink tmpfilename + end } end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/