ruby-changes:46835
From: nobu <ko1@a...>
Date: Mon, 29 May 2017 15:39:45 +0900 (JST)
Subject: [ruby-changes:46835] nobu:r58950 (trunk): ruby-runner.c: replace argv[0]
nobu 2017-05-29 15:39:41 +0900 (Mon, 29 May 2017) New Revision: 58950 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58950 Log: ruby-runner.c: replace argv[0] Modified files: trunk/ruby-runner.c Index: ruby-runner.c =================================================================== --- ruby-runner.c (revision 58949) +++ ruby-runner.c (revision 58950) @@ -12,6 +12,11 @@ int https://github.com/ruby/ruby/blob/trunk/ruby-runner.c#L12 main(int argc, char **argv) { static const char builddir[] = BUILDDIR; + static const char rubypath[] = BUILDDIR"/"STRINGIZE(RUBY_INSTALL_NAME); + const size_t dirsize = sizeof(builddir); + const size_t namesize = sizeof(rubypath) - dirsize; + const char *rubyname = rubypath + dirsize; + char *arg0 = argv[0], *p; const char *libpath = getenv(LIBPATHENV); char c = 0; @@ -20,16 +25,27 @@ main(int argc, char **argv) https://github.com/ruby/ruby/blob/trunk/ruby-runner.c#L25 } if (c) { size_t n = strlen(libpath); - char *e = malloc(sizeof(builddir)+n+1); - memcpy(e, builddir, sizeof(builddir)-1); - e[sizeof(builddir)-1] = PATH_SEP; - memcpy(e+sizeof(builddir), libpath, n+1); + char *e = malloc(dirsize+n+1); + memcpy(e, builddir, dirsize-1); + e[dirsize-1] = PATH_SEP; + memcpy(e+dirsize, libpath, n+1); libpath = e; } else { libpath = builddir; } setenv(LIBPATHENV, libpath, 1); - execv(BUILDDIR"/"STRINGIZE(RUBY_INSTALL_NAME), argv); + + if (!(p = strrchr(arg0, '/'))) p = arg0; else p++; + if (strlen(p) < namesize - 1) { + argv[0] = malloc(p - arg0 + namesize); + memcpy(argv[0], arg0, p - arg0); + memcpy(argv[0] + (p - arg0), rubypath + dirsize, namesize); + } + else { + memcpy(p, rubyname, namesize); + } + + execv(rubypath, argv); return -1; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/