aboutsummaryrefslogtreecommitdiffstats
path: root/ruby-runner.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-14 01:30:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-14 01:30:12 +0000
commit9319d3110475a18700dea917f188927cff73c1a1 (patch)
treec8e0689982671957d8cd976c903d3f211d4ca04b /ruby-runner.c
parent51ec61ae67debbd4e369fce024bfa53405b8126d (diff)
downloadruby-9319d3110475a18700dea917f188927cff73c1a1.tar.gz
ruby-runner.h
* template/ruby-runner.h.in: separate configured part from ruby-runner.c. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby-runner.c')
-rw-r--r--ruby-runner.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/ruby-runner.c b/ruby-runner.c
new file mode 100644
index 0000000000..c16e7c6829
--- /dev/null
+++ b/ruby-runner.c
@@ -0,0 +1,35 @@
+#define _POSIX_C_SOURCE 200809L
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "ruby-runner.h"
+
+#define STRINGIZE(expr) STRINGIZE0(expr)
+#define STRINGIZE0(expr) #expr
+
+int
+main(int argc, char **argv)
+{
+ static const char builddir[] = BUILDDIR;
+ const char *libpath = getenv(LIBPATHENV);
+ char c = 0;
+
+ if (libpath) {
+ while ((c = *libpath) == PATH_SEP) ++libpath;
+ }
+ 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);
+ libpath = e;
+ }
+ else {
+ libpath = builddir;
+ }
+ setenv(LIBPATHENV, libpath, 1);
+ execv(BUILDDIR"/"STRINGIZE(RUBY_INSTALL_NAME), argv);
+ return -1;
+}