summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-05-01 00:58:21 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-05-01 00:58:21 +0000
commit0886eb8ca81355488c2ef763790c5916030d10c4 (patch)
tree6d4d42beba408fc599bf7f71453d35089b9fa1bd /ruby.c
parent33fa9defffed4fa759d47e93c7c61a705780f1c5 (diff)
* 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/branches/ruby_1_8@8402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c54
1 files changed, 44 insertions, 10 deletions
diff --git a/ruby.c b/ruby.c
index a45a0d1..af265be 100644
--- a/ruby.c
+++ b/ruby.c
@@ -968,6 +968,33 @@ VALUE rb_progname;
VALUE rb_argv;
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
set_arg0(val, id)
VALUE val;
@@ -981,19 +1008,19 @@ set_arg0(val, id)
StringValue(val);
s = RSTRING(val)->ptr;
i = RSTRING(val)->len;
-#ifdef __hpux
+#if defined(PSTAT_SETCMD)
if (i >= PST_CLEN) {
- union pstun j;
- j.pst_command = s;
- i = PST_CLEN;
- RSTRING(val)->len = i;
- *(s + i) = '\0';
- pstat(PSTAT_SETCMD, j, PST_CLEN, 0, 0);
+ union pstun j;
+ j.pst_command = s;
+ i = PST_CLEN;
+ RSTRING(val)->len = i;
+ *(s + i) = '\0';
+ pstat(PSTAT_SETCMD, j, PST_CLEN, 0, 0);
}
else {
- union pstun j;
- j.pst_command = s;
- pstat(PSTAT_SETCMD, j, i, 0, 0);
+ union pstun j;
+ j.pst_command = s;
+ pstat(PSTAT_SETCMD, j, i, 0, 0);
}
rb_progname = rb_tainted_str_new(s, i);
#elif defined(HAVE_SETPROCTITLE)
@@ -1015,6 +1042,12 @@ set_arg0(val, id)
break;
}
}
+#ifndef DOSISH
+ if (s + 1 == envspace.begin) {
+ s = envspace.end;
+ ruby_setenv("", NULL); /* duplicate environ vars */
+ }
+#endif
len = s - origargv[0];
}
@@ -1150,6 +1183,7 @@ ruby_process_options(argc, argv)
#if defined(USE_DLN_A_OUT)
dln_argv0 = argv[0];
#endif
+ set_arg0space();
proc_options(argc, argv);
if (do_check && ruby_nerrs == 0) {