Feature #4046 ยป OS_ARGV_and_STARTUP_DIR.patch
include/ruby/ruby.h (working copy) | ||
---|---|---|
#include "ruby/subst.h"
|
||
#endif
|
||
struct origarg {
|
||
int argc;
|
||
char **argv;
|
||
char *os_startup_dir;
|
||
};
|
||
#if defined(__cplusplus)
|
||
#if 0
|
||
{ /* satisfy cc-mode */
|
vm.c (working copy) | ||
---|---|---|
return ary;
|
||
}
|
||
extern struct origarg origarg;
|
||
void
|
||
Init_VM(void)
|
||
{
|
||
... | ... | |
rb_undef_alloc_func(rb_cRubyVM);
|
||
rb_undef_method(CLASS_OF(rb_cRubyVM), "new");
|
||
/** ::VM::OS_ARGV and OS_STARTUP_DIR */
|
||
rb_define_const(rb_cRubyVM, "OS_STARTUP_DIR",
|
||
strlen(origarg.os_startup_dir) > 0 ?
|
||
rb_str_new2(origarg.os_startup_dir) : Qnil);
|
||
{
|
||
int argc;
|
||
char **argv;
|
||
VALUE ary = rb_ary_new();
|
||
rb_define_const(rb_cRubyVM, "OS_ARGV", ary);
|
||
for (argc = origarg.argc, argv = origarg.argv;
|
||
argc > 0; argc--, argv++) {
|
||
rb_ary_push(ary, rb_str_new2(*argv));
|
||
}
|
||
}
|
||
/* ::VM::FrozenCore */
|
||
fcore = rb_class_new(rb_cBasicObject);
|
||
RBASIC(fcore)->flags = T_ICLASS;
|
ruby.c (working copy) | ||
---|---|---|
static void forbid_setid(const char *, struct cmdline_options *);
|
||
#define forbid_setid(s) forbid_setid(s, opt)
|
||
static struct {
|
||
int argc;
|
||
char **argv;
|
||
struct origarg origarg;
|
||
#if !defined(PSTAT_SETCMD) && !defined(HAVE_SETPROCTITLE)
|
||
size_t len;
|
||
size_t origarg_len;
|
||
#endif
|
||
} origarg;
|
||
static void
|
||
usage(const char *name)
|
||
... | ... | |
setproctitle("%.*s", (int)i, s);
|
||
#else
|
||
if ((size_t)i > origarg.len - origarg.argc) {
|
||
i = (long)(origarg.len - origarg.argc);
|
||
if ((size_t)i > origarg_len - origarg.argc) {
|
||
i = (long)(origarg_len - origarg.argc);
|
||
}
|
||
memcpy(origarg.argv[0], s, i);
|
||
... | ... | |
char *t = origarg.argv[0] + i;
|
||
*t = '\0';
|
||
if ((size_t)(i + 1) < origarg.len) {
|
||
memset(t + 1, '\0', origarg.len - i - 1);
|
||
if ((size_t)(i + 1) < origarg_len) {
|
||
memset(t + 1, '\0', origarg_len - i - 1);
|
||
}
|
||
for (j = 1; j < origarg.argc; j++) {
|
||
origarg.argv[j] = t;
|
||
... | ... | |
#endif
|
||
origarg.argc = *argc;
|
||
origarg.argv = *argv;
|
||
origarg.os_startup_dir = malloc(MAXPATHLEN);
|
||
#ifdef HAVE_GETCWD
|
||
if (!getcwd(origarg.os_startup_dir, MAXPATHLEN))
|
||
origarg.os_startup_dir[0] = '\0';
|
||
#else
|
||
if (!getwd(origarg.os_startup_dir))
|
||
origarg.os_startup_dir[0] = '\0';
|
||
#endif
|
||
origarg.os_startup_dir = realloc(origarg.os_startup_dir,
|
||
strlen(origarg.os_startup_dir)+1);
|
||
#if !defined(PSTAT_SETCMD) && !defined(HAVE_SETPROCTITLE)
|
||
origarg.len = get_arglen(origarg.argc, origarg.argv);
|
||
origarg_len = get_arglen(origarg.argc, origarg.argv);
|
||
#endif
|
||
#if defined(USE_DLN_A_OUT)
|
||
dln_argv0 = origarg.argv[0];
|