渡辺哲也です。

$0 の件です。

In message "[ruby-list:11239] Re: variable $0"
    on 98/12/07, Yukihiro Matsumoto <matz / netlab.co.jp> writes:

|とりあえずこの対処を行います.SolarisやHP-UXでこの問題に対応

HP-UX では、こんな感じです。

pstat(2) というシステムコールがあり、このシステムコール
で対応します。公開されたのは HP-UX 10 からなのですが、
HP-UX 9.x から使えました(ヘッダファイルはもともとありま
した)。

動作するはずの HP-UX は、9 と 10 と 11 です。

HP-UX 11 の 64bit モードというのがあるのですが、これは
今月中にテストできる環境が使えますので、来週あたりにテ
ストして問題があれば、またお知らせします(多分大丈夫なは
ずですが)。

ruby-1.1c9 へのパッチになっています。

--
WATANABE Tetsuya HP Japan
 e-mail  Tetsuya_WATANABE / hp.com
         tetsu / jpn.hp.com

--- ruby.c.orig	Thu Sep  3 16:43:41 1998
+++ ruby.c	Mon Dec  7 18:24:50 1998
@@ -20,6 +20,10 @@
 #include <fcntl.h>
 #include <ctype.h>
 
+#ifdef __hpux
+#include <sys/pstat.h>
+#endif
+
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -615,6 +619,7 @@
     static int len;
 
     if (origargv == 0) Fail("$0 not initialized");
+#ifndef __hpux
     if (len == 0) {
 	s = origargv[0];
 	s += strlen(s);
@@ -625,7 +630,9 @@
 	}
 	len = s - origargv[0];
     }
+#endif
     s = str2cstr(val, &i);
+#ifndef __hpux
     if (i > len) {
 	memcpy(origargv[0], s, len);
 	origargv[0][len] = '\0';
@@ -638,6 +645,21 @@
 	    *s++ = ' ';
     }
     rb_progname = str_taint(str_new2(origargv[0]));
+#else
+    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);
+    } else {
+      union pstun j;
+      j.pst_command = s;
+      pstat(PSTAT_SETCMD, j, i, 0, 0);
+    }
+    rb_progname = str_taint(str_new(s, i));
+#endif
 }
 
 void