From e3f51e9064e191d34921bdaaa798bf154aec113f Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 10 Oct 2016 03:40:56 +0000 Subject: 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 --- ruby.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'ruby.c') 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; } } -- cgit v1.2.3