ruby-runner.c: replace argv[0]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f8fbb8bc11
commit
d4408a3d8b
@ -12,6 +12,11 @@ int
|
|||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
static const char builddir[] = BUILDDIR;
|
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);
|
const char *libpath = getenv(LIBPATHENV);
|
||||||
char c = 0;
|
char c = 0;
|
||||||
|
|
||||||
@ -20,16 +25,27 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (c) {
|
if (c) {
|
||||||
size_t n = strlen(libpath);
|
size_t n = strlen(libpath);
|
||||||
char *e = malloc(sizeof(builddir)+n+1);
|
char *e = malloc(dirsize+n+1);
|
||||||
memcpy(e, builddir, sizeof(builddir)-1);
|
memcpy(e, builddir, dirsize-1);
|
||||||
e[sizeof(builddir)-1] = PATH_SEP;
|
e[dirsize-1] = PATH_SEP;
|
||||||
memcpy(e+sizeof(builddir), libpath, n+1);
|
memcpy(e+dirsize, libpath, n+1);
|
||||||
libpath = e;
|
libpath = e;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
libpath = builddir;
|
libpath = builddir;
|
||||||
}
|
}
|
||||||
setenv(LIBPATHENV, libpath, 1);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user