1 #define _POSIX_C_SOURCE 200809L 8 #define STRINGIZE(expr) STRINGIZE0(expr) 9 #define STRINGIZE0(expr) #expr 12 insert_env_path(
const char *envname,
const char *paths,
size_t size,
int prepend)
21 while (n > 0 && env[n-1] ==
PATH_SEP) --n;
24 char *e =
malloc(size+n+1);
27 memcpy(e, paths, pos = size-1);
30 memcpy(e+pos, env, n);
34 memcpy(e+pos, paths, size-1);
43 setenv(envname, env, 1);
46 #define EXTOUT_DIR BUILDDIR"/"EXTOUT 50 static const char builddir[] =
BUILDDIR;
52 static const char rubylib[] =
59 const size_t dirsize =
sizeof(builddir);
60 const size_t namesize =
sizeof(rubypath) - dirsize;
61 const char *rubyname = rubypath + dirsize;
62 char *arg0 = argv[0], *p;
64 insert_env_path(
LIBPATHENV, builddir, dirsize, 1);
65 insert_env_path(
"RUBYLIB", rubylib,
sizeof(rubylib), 0);
67 if (!(p =
strrchr(arg0,
'/'))) p = arg0;
else p++;
68 if (
strlen(p) < namesize - 1) {
69 argv[0] =
malloc(p - arg0 + namesize);
70 memcpy(argv[0], arg0, p - arg0);
71 p = argv[0] + (p - arg0);
73 memcpy(p, rubyname, namesize);
75 execv(rubypath, argv);
int main(int argc, char **argv)
size_t strlen(const char *)
char * strrchr(const char *, const char)