From: Chip Salzenberg Date: Mon, 3 Feb 1997 23:16:46 +0000 (+1200) Subject: Fix value of system() and $? for DEC UNIX, VMS, others X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=91e9c03fe206e18256c19e5e5628ca536e8b1fd6;p=p5sagit%2Fp5-mst-13.2.git Fix value of system() and $? for DEC UNIX, VMS, others --- diff --git a/mg.c b/mg.c index 8c89e6b..77c0417 100644 --- a/mg.c +++ b/mg.c @@ -462,10 +462,7 @@ MAGIC *mg; #endif break; case '?': - if (STATUS_POSIX == -1) - sv_setiv(sv, (IV)-1); - else - sv_setuv(sv, (UV)STATUS_POSIX); + sv_setiv(sv, (IV)STATUS_POSIX); break; case '^': s = IoTOP_NAME(GvIOp(defoutgv)); @@ -1354,7 +1351,7 @@ MAGIC* mg; compiling.cop_arybase = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv); break; case '?': - STATUS_POSIX_SET(SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv)); + STATUS_POSIX_SET(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)); break; case '!': SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv), diff --git a/perl.h b/perl.h index f91179a..d267f20 100644 --- a/perl.h +++ b/perl.h @@ -444,7 +444,12 @@ #endif #define STATUS_POSIX statusvalue -#define STATUS_POSIX_SET(n) (statusvalue = (n)) +#define STATUS_POSIX_SET(n) \ + STMT_START { \ + statusvalue = (n); \ + if (statusvalue != -1) \ + statusvalue &= 0xFFFF; \ + } STMT_END #ifdef VMS # define STATUS_NATIVE statusvalue_vms @@ -468,8 +473,8 @@ # define STATUS_NATIVE STATUS_POSIX # define STATUS_NATIVE_EXPORT STATUS_POSIX # define STATUS_NATIVE_SET STATUS_POSIX_SET -# define STATUS_ALL_SUCCESS STATUS_POSIX_SET(0) -# define STATUS_ALL_FAILURE STATUS_POSIX_SET(1) +# define STATUS_ALL_SUCCESS (statusvalue = 0) +# define STATUS_ALL_FAILURE (statusvalue = 1) #endif #ifdef I_SYS_IOCTL @@ -1712,7 +1717,7 @@ IEXT STRLEN Iorslen; IEXT char * Iofmt; /* $# */ IEXT I32 Imaxsysfd IINIT(MAXSYSFD); /* top fd to pass to subprocesses */ IEXT int Imultiline; /* $*--do strings hold >1 line? */ -IEXT U32 Istatusvalue; /* $? */ +IEXT I32 Istatusvalue; /* $? */ #ifdef VMS IEXT U32 Istatusvalue_vms; /* $^S */ #endif diff --git a/pp_sys.c b/pp_sys.c index e593b6c..0be532f 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -2943,11 +2943,10 @@ PP(pp_system) } while (result == -1 && errno == EINTR); (void)rsignal_restore(SIGINT, &ihand); (void)rsignal_restore(SIGQUIT, &qhand); - STATUS_NATIVE_SET(status); - value = (result == -1) ? -1 : status; + STATUS_NATIVE_SET(result == -1 ? -1 : status); do_execfree(); /* free any memory child malloced on vfork */ SP = ORIGMARK; - PUSHi(value); + PUSHi(STATUS_POSIX); RETURN; } if (op->op_flags & OPf_STACKED) { @@ -2973,7 +2972,7 @@ PP(pp_system) STATUS_NATIVE_SET(value); do_execfree(); SP = ORIGMARK; - PUSHi(value); + PUSHi(STATUS_POSIX); #endif /* !FORK or VMS */ RETURN; }