ruby-changes:44313
From: nobu <ko1@a...>
Date: Mon, 10 Oct 2016 12:41:00 +0900 (JST)
Subject: [ruby-changes:44313] nobu:r56386 (trunk): ruby.c: compare with EXEEXT
nobu 2016-10-10 12:40:56 +0900 (Mon, 10 Oct 2016) New Revision: 56386 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56386 Log: 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. Modified files: trunk/ChangeLog trunk/ruby.c Index: ChangeLog =================================================================== --- ChangeLog (revision 56385) +++ ChangeLog (revision 56386) @@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Mon Oct 10 12:40:04 2016 Nobuyoshi Nakada <nobu@r...> +Mon Oct 10 12:40:54 2016 Nobuyoshi Nakada <nobu@r...> + + * 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. Index: ruby.c =================================================================== --- ruby.c (revision 56385) +++ ruby.c (revision 56386) @@ -1865,10 +1865,11 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ruby.c#L1865 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 https://github.com/ruby/ruby/blob/trunk/ruby.c#L1890 #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; } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/