summaryrefslogtreecommitdiff
path: root/ruby-runner.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-24 01:48:25 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-24 01:48:25 (GMT)
commit1d44d10b48bb812bf57fd657a2ac8960f9ba69c7 (patch)
tree8fc2b2ed096722881a2be5bd8e51674ffde5266f /ruby-runner.c
parenta2026d89fc5d2faf1c56608d4b01e22638d70e96 (diff)
ruby-runner.c: RUBYLIB
* ruby-runner.c (insert_env_path): extracted the function which insert path list to an environment variable. * ruby-runner.c (main): append library paths to RUBYLIB. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby-runner.c')
-rw-r--r--ruby-runner.c62
1 files changed, 45 insertions, 17 deletions
diff --git a/ruby-runner.c b/ruby-runner.c
index d0da883..99be4a0 100644
--- a/ruby-runner.c
+++ b/ruby-runner.c
@@ -8,33 +8,61 @@
#define STRINGIZE(expr) STRINGIZE0(expr)
#define STRINGIZE0(expr) #expr
+static void
+insert_env_path(const char *envname, const char *paths, size_t size, int prepend)
+{
+ const char *env = getenv(envname);
+ char c = 0;
+ size_t n = 0;
+
+ if (env) {
+ while ((c = *env) == PATH_SEP) ++env;
+ n = strlen(env);
+ while (n > 0 && env[n-1] == PATH_SEP) --n;
+ }
+ if (c) {
+ char *e = malloc(size+n+1);
+ size_t pos = 0;
+ if (prepend) {
+ memcpy(e, paths, pos = size-1);
+ e[pos++] = PATH_SEP;
+ }
+ memcpy(e+pos, env, n);
+ pos += n;
+ if (!prepend) {
+ e[pos++] = PATH_SEP;
+ memcpy(e+pos, paths, size-1);
+ pos += size-1;
+ }
+ e[pos] = '\0';
+ env = e;
+ }
+ else {
+ env = paths;
+ }
+ setenv(envname, env, 1);
+}
+
+#define EXTOUT_DIR BUILDDIR"/"EXTOUT
int
main(int argc, char **argv)
{
static const char builddir[] = BUILDDIR;
static const char rubypath[] = BUILDDIR"/"STRINGIZE(RUBY_INSTALL_NAME);
+ static const char rubylib[] =
+ ABS_SRCDIR"/lib"
+ PATH_SEPARATOR
+ EXTOUT_DIR"/common"
+ PATH_SEPARATOR
+ EXTOUT_DIR"/"ARCH
+ ;
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;
- if (libpath) {
- while ((c = *libpath) == PATH_SEP) ++libpath;
- }
- if (c) {
- size_t n = strlen(libpath);
- 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);
+ insert_env_path(LIBPATHENV, builddir, dirsize, 1);
+ insert_env_path("RUBYLIB", rubylib, sizeof(rubylib), 0);
if (!(p = strrchr(arg0, '/'))) p = arg0; else p++;
if (strlen(p) < namesize - 1) {