Ruby  2.4.2p198(2017-09-14revision59899)
ruby-runner.c
Go to the documentation of this file.
1 #define _POSIX_C_SOURCE 200809L
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
5 
6 #include "ruby-runner.h"
7 
8 #define STRINGIZE(expr) STRINGIZE0(expr)
9 #define STRINGIZE0(expr) #expr
10 
11 int
12 main(int argc, char **argv)
13 {
14  static const char builddir[] = BUILDDIR;
15  const char *libpath = getenv(LIBPATHENV);
16  char c = 0;
17 
18  if (libpath) {
19  while ((c = *libpath) == PATH_SEP) ++libpath;
20  }
21  if (c) {
22  size_t n = strlen(libpath);
23  char *e = malloc(sizeof(builddir)+n+1);
24  memcpy(e, builddir, sizeof(builddir)-1);
25  e[sizeof(builddir)-1] = PATH_SEP;
26  memcpy(e+sizeof(builddir), libpath, n+1);
27  libpath = e;
28  }
29  else {
30  libpath = builddir;
31  }
32  setenv(LIBPATHENV, libpath, 1);
33  execv(BUILDDIR"/"STRINGIZE(RUBY_INSTALL_NAME), argv);
34  return -1;
35 }
int main(int argc, char **argv)
Definition: ruby-runner.c:12
size_t strlen(const char *)
#define STRINGIZE(expr)
Definition: ruby-runner.c:8
int argc
Definition: ruby.c:183
#define malloc
Definition: ripper.c:116
#define getenv(name)
Definition: win32.c:71
#define PATH_SEP
Definition: defines.h:293
#define memcpy(d, s, n)
Definition: ffi_common.h:55
char ** argv
Definition: ruby.c:184