* ruby.c (set_arg0): use also environment variable space for setting
$0. [ruby-core:04774] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
35379dc7b7
commit
0dd5e501ad
@ -1,3 +1,8 @@
|
|||||||
|
Thu Apr 28 08:21:51 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ruby.c (set_arg0): use also environment variable space for setting
|
||||||
|
$0. [ruby-core:04774]
|
||||||
|
|
||||||
Wed Apr 27 23:42:22 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Apr 27 23:42:22 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* win32/Makefile.sub (OPTFLAGS): default global optimization to
|
* win32/Makefile.sub (OPTFLAGS): default global optimization to
|
||||||
|
54
ruby.c
54
ruby.c
@ -977,6 +977,33 @@ VALUE rb_progname;
|
|||||||
VALUE rb_argv;
|
VALUE rb_argv;
|
||||||
VALUE rb_argv0;
|
VALUE rb_argv0;
|
||||||
|
|
||||||
|
#if !defined(PSTAT_SETCMD) && !defined(HAVE_SETPROCTITLE) && !defined(DOSISH)
|
||||||
|
static struct {
|
||||||
|
char *begin, *end;
|
||||||
|
} envspace;
|
||||||
|
extern char **environ;
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_arg0space()
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!environ || (s = environ[0]) == NULL) return;
|
||||||
|
envspace.begin = s;
|
||||||
|
s += strlen(s);
|
||||||
|
for (i = 1; environ[i]; i++) {
|
||||||
|
if (environ[i] == s + 1) {
|
||||||
|
s++;
|
||||||
|
s += strlen(s); /* this one is ok too */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
envspace.end = s;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define set_arg0space() ((void)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_arg0(val, id)
|
set_arg0(val, id)
|
||||||
VALUE val;
|
VALUE val;
|
||||||
@ -990,19 +1017,19 @@ set_arg0(val, id)
|
|||||||
StringValue(val);
|
StringValue(val);
|
||||||
s = RSTRING(val)->ptr;
|
s = RSTRING(val)->ptr;
|
||||||
i = RSTRING(val)->len;
|
i = RSTRING(val)->len;
|
||||||
#ifdef __hpux
|
#if defined(PSTAT_SETCMD)
|
||||||
if (i >= PST_CLEN) {
|
if (i >= PST_CLEN) {
|
||||||
union pstun j;
|
union pstun j;
|
||||||
j.pst_command = s;
|
j.pst_command = s;
|
||||||
i = PST_CLEN;
|
i = PST_CLEN;
|
||||||
RSTRING(val)->len = i;
|
RSTRING(val)->len = i;
|
||||||
*(s + i) = '\0';
|
*(s + i) = '\0';
|
||||||
pstat(PSTAT_SETCMD, j, PST_CLEN, 0, 0);
|
pstat(PSTAT_SETCMD, j, PST_CLEN, 0, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
union pstun j;
|
union pstun j;
|
||||||
j.pst_command = s;
|
j.pst_command = s;
|
||||||
pstat(PSTAT_SETCMD, j, i, 0, 0);
|
pstat(PSTAT_SETCMD, j, i, 0, 0);
|
||||||
}
|
}
|
||||||
rb_progname = rb_tainted_str_new(s, i);
|
rb_progname = rb_tainted_str_new(s, i);
|
||||||
#elif defined(HAVE_SETPROCTITLE)
|
#elif defined(HAVE_SETPROCTITLE)
|
||||||
@ -1024,6 +1051,12 @@ set_arg0(val, id)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifndef DOSISH
|
||||||
|
if (s + 1 == envspace.begin) {
|
||||||
|
s = envspace.end;
|
||||||
|
ruby_setenv("", NULL); /* duplicate environ vars */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
len = s - origargv[0];
|
len = s - origargv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1174,6 +1207,7 @@ ruby_process_options(argc, argv)
|
|||||||
#if defined(USE_DLN_A_OUT)
|
#if defined(USE_DLN_A_OUT)
|
||||||
dln_argv0 = argv[0];
|
dln_argv0 = argv[0];
|
||||||
#endif
|
#endif
|
||||||
|
set_arg0space();
|
||||||
proc_options(argc, argv);
|
proc_options(argc, argv);
|
||||||
|
|
||||||
if (do_check && ruby_nerrs == 0) {
|
if (do_check && ruby_nerrs == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user