aboutsummaryrefslogtreecommitdiffstats
path: root/ruby.c
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 /ruby.c
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
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c10
1 files changed, 7 insertions, 3 deletions
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;
}
}