summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-10 09:36:08 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-10 09:36:08 +0000
commite7023df46a6cca0249c0eafc3521b8d9134ed0e7 (patch)
tree9a3f2ff2d4c583ae03d28d4da09819c6796dba1a /ruby.c
parentd83a42aac2319b70a4e9a163dd619aca085ec1c4 (diff)
merge revision(s) 17849:
* ruby.c: Mac OS X needs origargc times of '\0' in origargv. [ruby-dev:35308] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@17994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c64
1 files changed, 40 insertions, 24 deletions
diff --git a/ruby.c b/ruby.c
index dafca05..6fbb6d2 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1029,6 +1029,39 @@ set_arg0space()
#define set_arg0space() ((void)0)
#endif
+static int
+get_arglen(int argc, char **argv)
+{
+ char *s = argv[0];
+ int i;
+
+ if (!argc) return 0;
+ s += strlen(s);
+ /* See if all the arguments are contiguous in memory */
+ for (i = 1; i < argc; i++) {
+ if (argv[i] == s + 1) {
+ s++;
+ s += strlen(s); /* this one is ok too */
+ }
+ else {
+ break;
+ }
+ }
+#if defined(USE_ENVSPACE_FOR_ARG0)
+ if (environ && (s == environ[0])) {
+ s += strlen(s);
+ for (i = 1; environ[i]; i++) {
+ if (environ[i] == s + 1) {
+ s++;
+ s += strlen(s); /* this one is ok too */
+ }
+ }
+ ruby_setenv("", NULL); /* duplicate environ vars */
+ }
+#endif
+ return s - argv[0];
+}
+
static void
set_arg0(val, id)
VALUE val;
@@ -1037,8 +1070,9 @@ set_arg0(val, id)
VALUE progname;
char *s;
long i;
+ int j;
#if !defined(PSTAT_SETCMD) && !defined(HAVE_SETPROCTITLE)
- static int len;
+ static int len = 0;
#endif
if (origargv == 0) rb_raise(rb_eRuntimeError, "$0 not initialized");
@@ -1065,27 +1099,7 @@ set_arg0(val, id)
progname = rb_tainted_str_new(s, i);
#else
if (len == 0) {
- char *s = origargv[0];
- int i;
-
- s += strlen(s);
- /* See if all the arguments are contiguous in memory */
- for (i = 1; i < origargc; i++) {
- if (origargv[i] == s + 1) {
- s++;
- s += strlen(s); /* this one is ok too */
- }
- else {
- break;
- }
- }
-#if defined(USE_ENVSPACE_FOR_ARG0)
- if (s + 1 == envspace.begin) {
- s = envspace.end;
- ruby_setenv("", NULL); /* duplicate environ vars */
- }
-#endif
- len = s - origargv[0];
+ len = get_arglen(origargc, origargv);
}
if (i >= len) {
@@ -1095,8 +1109,10 @@ set_arg0(val, id)
s = origargv[0] + i;
*s = '\0';
if (++i < len) memset(s + 1, ' ', len - i);
- for (i = 1; i < origargc; i++)
- origargv[i] = s;
+ for (i = len-1, j = origargc-1; j > 0 && i >= 0; --i, --j) {
+ origargv[j] = origargv[0] + i;
+ *origargv[j] = '\0';
+ }
progname = rb_tainted_str_new2(origargv[0]);
#endif
rb_progname = rb_obj_freeze(progname);