aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-10 03:40:56 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-10 03:40:56 +0000
commite3f51e9064e191d34921bdaaa798bf154aec113f (patch)
tree8bf6fdecafe641f40cbb93f9cd676ddb40ce524f
parentdbeed155a05b7e82dffc8f43a5918cb5a8efbbfb (diff)
downloadruby-e3f51e9064e191d34921bdaaa798bf154aec113f.tar.gz
ruby.c: compare with EXEEXT
* ruby.c (open_load_file): compare with EXEEXT instead of hard coded name, and do not match with mere EXEEXT. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56386 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ruby.c10
2 files changed, 11 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index e98a60b406..16d43145dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Mon Oct 10 12:40:04 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Oct 10 12:40:54 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ruby.c (open_load_file): compare with EXEEXT instead of hard
+ coded name, and do not match with mere EXEEXT.
* ruby.c (open_load_file): open in binary mode if available, as
parser deals with EOLs.
diff --git a/ruby.c b/ruby.c
index 5f4ee53c92..8678bcce2c 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1865,10 +1865,11 @@ static VALUE
open_load_file(VALUE fname_v, int *xflag)
{
const char *fname = StringValueCStr(fname_v);
+ long flen = RSTRING_LEN(fname_v);
VALUE f;
int e;
- if (RSTRING_LEN(fname_v) == 1 && fname[0] == '-') {
+ if (flen == 1 && fname[0] == '-') {
f = rb_stdin;
}
else {
@@ -1889,9 +1890,12 @@ open_load_file(VALUE fname_v, int *xflag)
#endif
MODE_TO_LOAD;
#if defined DOSISH || defined __CYGWIN__
+# define isdirsep(x) ((x) == '/' || (x) == FILE_ALT_SEPARATOR)
{
- const char *ext = strrchr(fname, '.');
- if (ext && STRCASECMP(ext, ".exe") == 0) {
+ static const char exeext[] = EXEEXT;
+ enum {extlen = sizeof(exeext)-1};
+ if (flen > extlen && !isdirsep(fname[flen-extlen-1]) &&
+ STRNCASECMP(fname+flen-extlen, exeext, extlen) == 0) {
*xflag = 1;
}
}