Re: The Inaba patch for tr/// vs. use encoding
[p5sagit/p5-mst-13.2.git] / pp_sys.c
index 4760210..f1eb1b9 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -82,6 +82,8 @@ extern int h_errno;
 # ifdef HAS_GETPWENT
 #ifndef getpwent
   struct passwd *getpwent (void);
+#elif defined (VMS) && defined (my_getpwent)
+  struct passwd *Perl_my_getpwent (void);
 #endif
 # endif
 #endif
@@ -171,6 +173,8 @@ static char zero_but_true[ZBTLEN + 1] = "0 but true";
 #  define FD_CLOEXEC 1         /* NeXT needs this */
 #endif
 
+#include "reentr.h"
+
 #undef PERL_EFF_ACCESS_R_OK    /* EFFective uid/gid ACCESS R_OK */
 #undef PERL_EFF_ACCESS_W_OK
 #undef PERL_EFF_ACCESS_X_OK
@@ -319,10 +323,13 @@ PP(pp_backtick)
                ;
        }
        else if (gimme == G_SCALAR) {
+           SV *oldrs = PL_rs;
+           PL_rs = &PL_sv_undef;
            sv_setpv(TARG, ""); /* note that this preserves previous buffer */
            while (sv_gets(TARG, fp, SvCUR(TARG)) != Nullch)
                /*SUPPRESS 530*/
                ;
+           PL_rs = oldrs;
            XPUSHs(TARG);
            SvTAINTED_on(TARG);
        }
@@ -450,7 +457,7 @@ PP(pp_die)
     }
     else {
        tmpsv = TOPs;
-        tmps = (SvROK(tmpsv) && PL_in_eval) ? Nullch : SvPV(tmpsv, len);
+        tmps = SvROK(tmpsv) ? Nullch : SvPV(tmpsv, len);
     }
     if (!tmps || !len) {
        SV *error = ERRSV;
@@ -601,8 +608,9 @@ PP(pp_pipe_op)
     if (PerlProc_pipe(fd) < 0)
        goto badexit;
 
-    IoIFP(rstio) = PerlIO_fdopen(fd[0], "r");
-    IoOFP(wstio) = PerlIO_fdopen(fd[1], "w");
+    IoIFP(rstio) = PerlIO_fdopen(fd[0], "r"PIPESOCK_MODE);
+    IoOFP(wstio) = PerlIO_fdopen(fd[1], "w"PIPESOCK_MODE);
+    IoOFP(rstio) = IoIFP(rstio);
     IoIFP(wstio) = IoOFP(wstio);
     IoTYPE(rstio) = IoTYPE_RDONLY;
     IoTYPE(wstio) = IoTYPE_WRONLY;
@@ -726,14 +734,20 @@ PP(pp_binmode)
     if (!(io = GvIO(gv)) || !(fp = IoIFP(io))) {
        if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
            report_evil_fh(gv, io, PL_op->op_type);
+       SETERRNO(EBADF,RMS_IFI);
         RETPUSHUNDEF;
     }
 
+    PUTBACK;
     if (PerlIO_binmode(aTHX_ fp,IoTYPE(io),mode_from_discipline(discp),
-                       (discp) ? SvPV_nolen(discp) : Nullch))
+                       (discp) ? SvPV_nolen(discp) : Nullch)) {
+       SPAGAIN;
        RETPUSHYES;
-    else
+    }
+    else {
+       SPAGAIN;
        RETPUSHUNDEF;
+    }
 }
 
 PP(pp_tie)
@@ -783,7 +797,7 @@ PP(pp_tie)
        ENTER;
        PUSHSTACKi(PERLSI_MAGIC);
        PUSHMARK(SP);
-       EXTEND(SP,items);
+       EXTEND(SP,(I32)items);
        while (items--)
            PUSHs(*MARK++);
        PUTBACK;
@@ -801,7 +815,7 @@ PP(pp_tie)
        ENTER;
        PUSHSTACKi(PERLSI_MAGIC);
        PUSHMARK(SP);
-       EXTEND(SP,items);
+       EXTEND(SP,(I32)items);
        while (items--)
            PUSHs(*MARK++);
        PUTBACK;
@@ -815,11 +829,11 @@ PP(pp_tie)
        sv_unmagic(varsv, how);
        /* Croak if a self-tie on an aggregate is attempted. */
        if (varsv == SvRV(sv) &&
-           (SvTYPE(sv) == SVt_PVAV ||
-            SvTYPE(sv) == SVt_PVHV))
+           (SvTYPE(varsv) == SVt_PVAV ||
+            SvTYPE(varsv) == SVt_PVHV))
            Perl_croak(aTHX_
                       "Self-ties of arrays and hashes are not supported");
-       sv_magic(varsv, sv, how, Nullch, 0);
+       sv_magic(varsv, (SvRV(sv) == varsv ? Nullsv : sv), how, Nullch, 0);
     }
     LEAVE;
     SP = PL_stack_base + markoff;
@@ -1164,6 +1178,7 @@ PP(pp_getc)
        if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)
                && (!io || (!IoIFP(io) && IoTYPE(io) != IoTYPE_WRONLY)))
            report_evil_fh(gv, io, PL_op->op_type);
+       SETERRNO(EBADF,RMS_IFI);
        RETPUSHUNDEF;
     }
     TAINT;
@@ -1193,8 +1208,6 @@ S_doform(pTHX_ CV *cv, GV *gv, OP *retop)
 {
     register PERL_CONTEXT *cx;
     I32 gimme = GIMME_V;
-    AV* padlist = CvPADLIST(cv);
-    SV** svp = AvARRAY(padlist);
 
     ENTER;
     SAVETMPS;
@@ -1202,8 +1215,7 @@ S_doform(pTHX_ CV *cv, GV *gv, OP *retop)
     push_return(retop);
     PUSHBLOCK(cx, CXt_FORMAT, PL_stack_sp);
     PUSHFORMAT(cx);
-    SAVEVPTR(PL_curpad);
-    PL_curpad = AvARRAY((AV*)svp[1]);
+    PAD_SET_CUR(CvPADLIST(cv), 1);
 
     setdefout(gv);         /* locally select filehandle so $% et al work */
     return CvSTART(cv);
@@ -1434,7 +1446,7 @@ PP(pp_prtf)
     if (!(io = GvIO(gv))) {
        if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
            report_evil_fh(gv, io, PL_op->op_type);
-       SETERRNO(EBADF,RMS$_IFI);
+       SETERRNO(EBADF,RMS_IFI);
        goto just_say_no;
     }
     else if (!(fp = IoOFP(io))) {
@@ -1456,7 +1468,7 @@ PP(pp_prtf)
            else if (ckWARN(WARN_CLOSED))
                report_evil_fh(gv, io, PL_op->op_type);
        }
-       SETERRNO(EBADF,IoIFP(io)?RMS$_FAC:RMS$_IFI);
+       SETERRNO(EBADF,IoIFP(io)?RMS_FAC:RMS_IFI);
        goto just_say_no;
     }
     else {
@@ -1561,8 +1573,12 @@ PP(pp_sysread)
     else
        offset = 0;
     io = GvIO(gv);
-    if (!io || !IoIFP(io))
+    if (!io || !IoIFP(io)) {
+       if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
+           report_evil_fh(gv, io, PL_op->op_type);
+       SETERRNO(EBADF,RMS_IFI);
        goto say_undef;
+    }
     if ((fp_utf8 = PerlIO_isutf8(IoIFP(io))) && !IN_BYTES) {
        buffer = SvPVutf8_force(bufsv, blen);
        /* UTF8 may not have been set if they are all low bytes */
@@ -1582,7 +1598,7 @@ PP(pp_sysread)
 #ifdef HAS_SOCKET
     if (PL_op->op_type == OP_RECV) {
        char namebuf[MAXPATHLEN];
-#if (defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS)) || defined(MPE)
+#if (defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS)) || defined(MPE) || defined(__QNXNTO__)
        bufsize = sizeof (struct sockaddr_in);
 #else
        bufsize = sizeof namebuf;
@@ -1591,7 +1607,7 @@ PP(pp_sysread)
        if (bufsize >= 256)
            bufsize = 255;
 #endif
-       buffer = SvGROW(bufsv, length+1);
+       buffer = SvGROW(bufsv, (STRLEN)(length+1));
        /* 'offset' means 'flags' here */
        count = PerlSock_recvfrom(PerlIO_fileno(IoIFP(io)), buffer, length, offset,
                          (struct sockaddr *)namebuf, &bufsize);
@@ -1624,7 +1640,7 @@ PP(pp_sysread)
        blen = sv_len_utf8(bufsv);
     }
     if (offset < 0) {
-       if (-offset > blen)
+       if (-offset > (int)blen)
            DIE(aTHX_ "Offset outside string");
        offset += blen;
     }
@@ -1634,7 +1650,7 @@ PP(pp_sysread)
     }
  more_bytes:
     bufsize = SvCUR(bufsv);
-    buffer  = SvGROW(bufsv, length+offset+1);
+    buffer  = SvGROW(bufsv, (STRLEN)(length+offset+1));
     if (offset > bufsize) { /* Zero any newly allocated space */
        Zero(buffer+bufsize, offset-bufsize, char);
     }
@@ -1803,6 +1819,7 @@ PP(pp_send)
        retval = -1;
        if (ckWARN(WARN_CLOSED))
            report_evil_fh(gv, io, PL_op->op_type);
+       SETERRNO(EBADF,RMS_IFI);
        goto say_undef;
     }
 
@@ -1824,10 +1841,10 @@ PP(pp_send)
        if (MARK < SP) {
            offset = SvIVx(*++MARK);
            if (offset < 0) {
-               if (-offset > blen)
+               if (-offset > (IV)blen)
                    DIE(aTHX_ "Offset outside string");
                offset += blen;
-           } else if (offset >= blen && blen > 0)
+           } else if (offset >= (IV)blen && blen > 0)
                DIE(aTHX_ "Offset outside string");
        } else
            offset = 0;
@@ -2040,7 +2057,7 @@ PP(pp_truncate)
     /* XXX Configure probe for the length type of *truncate() needed XXX */
     Off_t len;
 
-#if Size_t_size > IVSIZE
+#if Off_t_size > IVSIZE
     len = (Off_t)POPn;
 #else
     len = (Off_t)POPi;
@@ -2108,7 +2125,7 @@ PP(pp_truncate)
        if (result)
            RETPUSHYES;
        if (!errno)
-           SETERRNO(EBADF,RMS$_IFI);
+           SETERRNO(EBADF,RMS_IFI);
        RETPUSHUNDEF;
     }
 #else
@@ -2135,7 +2152,7 @@ PP(pp_ioctl)
     if (!io || !argsv || !IoIFP(io)) {
        if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
            report_evil_fh(gv, io, PL_op->op_type);
-       SETERRNO(EBADF,RMS$_IFI);       /* well, sort of... */
+       SETERRNO(EBADF,RMS_IFI);        /* well, sort of... */
        RETPUSHUNDEF;
     }
 
@@ -2165,15 +2182,14 @@ PP(pp_ioctl)
        DIE(aTHX_ "ioctl is not implemented");
 #endif
     else
-#ifdef HAS_FCNTL
+#ifndef HAS_FCNTL
+      DIE(aTHX_ "fcntl is not implemented");
+#else
 #if defined(OS2) && defined(__EMX__)
        retval = fcntl(PerlIO_fileno(IoIFP(io)), func, (int)s);
 #else
        retval = fcntl(PerlIO_fileno(IoIFP(io)), func, s);
 #endif
-#else
-       DIE(aTHX_ "fcntl is not implemented");
-#endif
 
     if (SvPOK(argsv)) {
        if (s[SvCUR(argsv)] != 17)
@@ -2191,6 +2207,7 @@ PP(pp_ioctl)
     else {
        PUSHp(zero_but_true, ZBTLEN);
     }
+#endif
     RETURN;
 }
 
@@ -2223,7 +2240,7 @@ PP(pp_flock)
        if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
            report_evil_fh(gv, io, PL_op->op_type);
        value = 0;
-       SETERRNO(EBADF,RMS$_IFI);
+       SETERRNO(EBADF,RMS_IFI);
     }
     PUSHi(value);
     RETURN;
@@ -2253,7 +2270,7 @@ PP(pp_socket)
            report_evil_fh(gv, io, PL_op->op_type);
        if (IoIFP(io))
            do_close(gv, FALSE);
-       SETERRNO(EBADF,LIB$_INVARG);
+       SETERRNO(EBADF,LIB_INVARG);
        RETPUSHUNDEF;
     }
 
@@ -2264,8 +2281,8 @@ PP(pp_socket)
     fd = PerlSock_socket(domain, type, protocol);
     if (fd < 0)
        RETPUSHUNDEF;
-    IoIFP(io) = PerlIO_fdopen(fd, "r");        /* stdio gets confused about sockets */
-    IoOFP(io) = PerlIO_fdopen(fd, "w");
+    IoIFP(io) = PerlIO_fdopen(fd, "r"PIPESOCK_MODE);   /* stdio gets confused about sockets */
+    IoOFP(io) = PerlIO_fdopen(fd, "w"PIPESOCK_MODE);
     IoTYPE(io) = IoTYPE_SOCKET;
     if (!IoIFP(io) || !IoOFP(io)) {
        if (IoIFP(io)) PerlIO_close(IoIFP(io));
@@ -2326,11 +2343,11 @@ PP(pp_sockpair)
     TAINT_PROPER("socketpair");
     if (PerlSock_socketpair(domain, type, protocol, fd) < 0)
        RETPUSHUNDEF;
-    IoIFP(io1) = PerlIO_fdopen(fd[0], "r");
-    IoOFP(io1) = PerlIO_fdopen(fd[0], "w");
+    IoIFP(io1) = PerlIO_fdopen(fd[0], "r"PIPESOCK_MODE);
+    IoOFP(io1) = PerlIO_fdopen(fd[0], "w"PIPESOCK_MODE);
     IoTYPE(io1) = IoTYPE_SOCKET;
-    IoIFP(io2) = PerlIO_fdopen(fd[1], "r");
-    IoOFP(io2) = PerlIO_fdopen(fd[1], "w");
+    IoIFP(io2) = PerlIO_fdopen(fd[1], "r"PIPESOCK_MODE);
+    IoOFP(io2) = PerlIO_fdopen(fd[1], "w"PIPESOCK_MODE);
     IoTYPE(io2) = IoTYPE_SOCKET;
     if (!IoIFP(io1) || !IoOFP(io1) || !IoIFP(io2) || !IoOFP(io2)) {
        if (IoIFP(io1)) PerlIO_close(IoIFP(io1));
@@ -2404,7 +2421,7 @@ PP(pp_bind)
 nuts:
     if (ckWARN(WARN_CLOSED))
        report_evil_fh(gv, io, PL_op->op_type);
-    SETERRNO(EBADF,SS$_IVCHAN);
+    SETERRNO(EBADF,SS_IVCHAN);
     RETPUSHUNDEF;
 #else
     DIE(aTHX_ PL_no_sock_func, "bind");
@@ -2434,7 +2451,7 @@ PP(pp_connect)
 nuts:
     if (ckWARN(WARN_CLOSED))
        report_evil_fh(gv, io, PL_op->op_type);
-    SETERRNO(EBADF,SS$_IVCHAN);
+    SETERRNO(EBADF,SS_IVCHAN);
     RETPUSHUNDEF;
 #else
     DIE(aTHX_ PL_no_sock_func, "connect");
@@ -2460,7 +2477,7 @@ PP(pp_listen)
 nuts:
     if (ckWARN(WARN_CLOSED))
        report_evil_fh(gv, io, PL_op->op_type);
-    SETERRNO(EBADF,SS$_IVCHAN);
+    SETERRNO(EBADF,SS_IVCHAN);
     RETPUSHUNDEF;
 #else
     DIE(aTHX_ PL_no_sock_func, "listen");
@@ -2498,12 +2515,12 @@ PP(pp_accept)
        goto badexit;
     if (IoIFP(nstio))
        do_close(ngv, FALSE);
-    IoIFP(nstio) = PerlIO_fdopen(fd, "r");
+    IoIFP(nstio) = PerlIO_fdopen(fd, "r"PIPESOCK_MODE);
     /* FIXME: we dup(fd) here so that refcounting of fd's does not inhibit
        fclose of IoOFP's FILE * - and hence leak memory.
        Special treatment of _this_ case of IoIFP != IoOFP seems wrong.
      */
-    IoOFP(nstio) = PerlIO_fdopen(fd2 = PerlLIO_dup(fd), "w");
+    IoOFP(nstio) = PerlIO_fdopen(fd2 = PerlLIO_dup(fd), "w"PIPESOCK_MODE);
     IoTYPE(nstio) = IoTYPE_SOCKET;
     if (!IoIFP(nstio) || !IoOFP(nstio)) {
        if (IoIFP(nstio)) PerlIO_close(IoIFP(nstio));
@@ -2527,7 +2544,7 @@ PP(pp_accept)
 nuts:
     if (ckWARN(WARN_CLOSED))
        report_evil_fh(ggv, ggv ? GvIO(ggv) : 0, PL_op->op_type);
-    SETERRNO(EBADF,SS$_IVCHAN);
+    SETERRNO(EBADF,SS_IVCHAN);
 
 badexit:
     RETPUSHUNDEF;
@@ -2554,7 +2571,7 @@ PP(pp_shutdown)
 nuts:
     if (ckWARN(WARN_CLOSED))
        report_evil_fh(gv, io, PL_op->op_type);
-    SETERRNO(EBADF,SS$_IVCHAN);
+    SETERRNO(EBADF,SS_IVCHAN);
     RETPUSHUNDEF;
 #else
     DIE(aTHX_ PL_no_sock_func, "shutdown");
@@ -2633,7 +2650,7 @@ PP(pp_ssockopt)
 nuts:
     if (ckWARN(WARN_CLOSED))
        report_evil_fh(gv, io, optype);
-    SETERRNO(EBADF,SS$_IVCHAN);
+    SETERRNO(EBADF,SS_IVCHAN);
 nuts2:
     RETPUSHUNDEF;
 
@@ -2706,7 +2723,7 @@ PP(pp_getpeername)
 nuts:
     if (ckWARN(WARN_CLOSED))
        report_evil_fh(gv, io, optype);
-    SETERRNO(EBADF,SS$_IVCHAN);
+    SETERRNO(EBADF,SS_IVCHAN);
 nuts2:
     RETPUSHUNDEF;
 
@@ -3312,7 +3329,7 @@ PP(pp_fttext)
                gv = cGVOP_gv;
                report_evil_fh(gv, GvIO(gv), PL_op->op_type);
            }
-           SETERRNO(EBADF,RMS$_IFI);
+           SETERRNO(EBADF,RMS_IFI);
            RETPUSHUNDEF;
        }
     }
@@ -3641,21 +3658,21 @@ S_dooneliner(pTHX_ char *cmd, char *filename)
 #define EACCES EPERM
 #endif
            if (instr(s, "cannot make"))
-               SETERRNO(EEXIST,RMS$_FEX);
+               SETERRNO(EEXIST,RMS_FEX);
            else if (instr(s, "existing file"))
-               SETERRNO(EEXIST,RMS$_FEX);
+               SETERRNO(EEXIST,RMS_FEX);
            else if (instr(s, "ile exists"))
-               SETERRNO(EEXIST,RMS$_FEX);
+               SETERRNO(EEXIST,RMS_FEX);
            else if (instr(s, "non-exist"))
-               SETERRNO(ENOENT,RMS$_FNF);
+               SETERRNO(ENOENT,RMS_FNF);
            else if (instr(s, "does not exist"))
-               SETERRNO(ENOENT,RMS$_FNF);
+               SETERRNO(ENOENT,RMS_FNF);
            else if (instr(s, "not empty"))
-               SETERRNO(EBUSY,SS$_DEVOFFLINE);
+               SETERRNO(EBUSY,SS_DEVOFFLINE);
            else if (instr(s, "cannot access"))
-               SETERRNO(EACCES,RMS$_PRV);
+               SETERRNO(EACCES,RMS_PRV);
            else
-               SETERRNO(EPERM,RMS$_PRV);
+               SETERRNO(EPERM,RMS_PRV);
            return 0;
        }
        else {  /* some mkdirs return no failure indication */
@@ -3665,7 +3682,7 @@ S_dooneliner(pTHX_ char *cmd, char *filename)
            if (anum)
                SETERRNO(0,0);
            else
-               SETERRNO(EACCES,RMS$_PRV);      /* a guess */
+               SETERRNO(EACCES,RMS_PRV);       /* a guess */
        }
        return anum;
     }
@@ -3701,7 +3718,7 @@ PP(pp_mkdir)
      * -d, chdir(), chmod(), chown(), chroot(), fcntl()?,
      * (mkdir()), opendir(), rename(), rmdir(), stat(). --jhi */
     if (len > 1 && tmps[len-1] == '/') {
-       while (tmps[len] == '/' && len > 1)
+       while (tmps[len-1] == '/' && len > 1)
            len--;
        tmps = savepvn(tmps, len);
        copy = TRUE;
@@ -3759,7 +3776,7 @@ PP(pp_open_dir)
     RETPUSHYES;
 nope:
     if (!errno)
-       SETERRNO(EBADF,RMS$_DIR);
+       SETERRNO(EBADF,RMS_DIR);
     RETPUSHUNDEF;
 #else
     DIE(aTHX_ PL_no_dir_func, "opendir");
@@ -3814,7 +3831,7 @@ PP(pp_readdir)
 
 nope:
     if (!errno)
-       SETERRNO(EBADF,RMS$_ISI);
+       SETERRNO(EBADF,RMS_ISI);
     if (GIMME == G_ARRAY)
        RETURN;
     else
@@ -3845,7 +3862,7 @@ PP(pp_telldir)
     RETURN;
 nope:
     if (!errno)
-       SETERRNO(EBADF,RMS$_ISI);
+       SETERRNO(EBADF,RMS_ISI);
     RETPUSHUNDEF;
 #else
     DIE(aTHX_ PL_no_dir_func, "telldir");
@@ -3868,7 +3885,7 @@ PP(pp_seekdir)
     RETPUSHYES;
 nope:
     if (!errno)
-       SETERRNO(EBADF,RMS$_ISI);
+       SETERRNO(EBADF,RMS_ISI);
     RETPUSHUNDEF;
 #else
     DIE(aTHX_ PL_no_dir_func, "seekdir");
@@ -3889,7 +3906,7 @@ PP(pp_rewinddir)
     RETPUSHYES;
 nope:
     if (!errno)
-       SETERRNO(EBADF,RMS$_ISI);
+       SETERRNO(EBADF,RMS_ISI);
     RETPUSHUNDEF;
 #else
     DIE(aTHX_ PL_no_dir_func, "rewinddir");
@@ -3919,7 +3936,7 @@ PP(pp_closedir)
     RETPUSHYES;
 nope:
     if (!errno)
-       SETERRNO(EBADF,RMS$_IFI);
+       SETERRNO(EBADF,RMS_IFI);
     RETPUSHUNDEF;
 #else
     DIE(aTHX_ PL_no_dir_func, "closedir");
@@ -3947,6 +3964,9 @@ PP(pp_fork)
            sv_setiv(GvSV(tmpgv), (IV)PerlProc_getpid());
             SvREADONLY_on(GvSV(tmpgv));
         }
+#ifdef THREADS_HAVE_PIDS
+       PL_ppid = (IV)getppid();
+#endif
        hv_clear(PL_pidstatus); /* no kids, so don't wait for 'em */
     }
     PUSHi(childpid);
@@ -4032,114 +4052,117 @@ PP(pp_system)
     I32 value;
     STRLEN n_a;
     int result;
-    int pp[2];
     I32 did_pipes = 0;
 
     if (PL_tainting) {
        TAINT_ENV();
        while (++MARK <= SP) {
            (void)SvPV_nolen(*MARK);      /* stringify for taint check */
-           if (PL_tainted) 
+           if (PL_tainted)
                break;
        }
        MARK = ORIGMARK;
-       /* XXX Remove warning at end of deprecation cycle --RD 2002-02  */
-       if (SP - MARK == 1) {
-           TAINT_PROPER("system");
-       }
-       else if (ckWARN2(WARN_TAINT, WARN_DEPRECATED)) {
-           Perl_warner(aTHX_ packWARN2(WARN_TAINT, WARN_DEPRECATED),
-               "Use of tainted arguments in %s is deprecated", "system");
-       }
+       TAINT_PROPER("system");
     }
     PERL_FLUSHALL_FOR_CHILD;
 #if (defined(HAS_FORK) || defined(AMIGAOS)) && !defined(VMS) && !defined(OS2) || defined(PERL_MICRO)
     {
-        Pid_t childpid;
-        int status;
-        Sigsave_t ihand,qhand;     /* place to save signals during system() */
-
-        if (PerlProc_pipe(pp) >= 0)
-             did_pipes = 1;
-        while ((childpid = PerlProc_fork()) == -1) {
-             if (errno != EAGAIN) {
-                  value = -1;
-                  SP = ORIGMARK;
-                  PUSHi(value);
-                  if (did_pipes) {
-                       PerlLIO_close(pp[0]);
-                       PerlLIO_close(pp[1]);
-                  }
-                  RETURN;
-             }
-             sleep(5);
-        }
-        if (childpid > 0) {
-             if (did_pipes)
-                  PerlLIO_close(pp[1]);
+       Pid_t childpid;
+       int pp[2];
+
+       if (PerlProc_pipe(pp) >= 0)
+           did_pipes = 1;
+       while ((childpid = PerlProc_fork()) == -1) {
+           if (errno != EAGAIN) {
+               value = -1;
+               SP = ORIGMARK;
+               PUSHi(value);
+               if (did_pipes) {
+                   PerlLIO_close(pp[0]);
+                   PerlLIO_close(pp[1]);
+               }
+               RETURN;
+           }
+           sleep(5);
+       }
+       if (childpid > 0) {
+           Sigsave_t ihand,qhand; /* place to save signals during system() */
+           int status;
+
+           if (did_pipes)
+               PerlLIO_close(pp[1]);
 #ifndef PERL_MICRO
-             rsignal_save(SIGINT, SIG_IGN, &ihand);
-             rsignal_save(SIGQUIT, SIG_IGN, &qhand);
+           rsignal_save(SIGINT, SIG_IGN, &ihand);
+           rsignal_save(SIGQUIT, SIG_IGN, &qhand);
 #endif
-             do {
-                  result = wait4pid(childpid, &status, 0);
-             } while (result == -1 && errno == EINTR);
+           do {
+               result = wait4pid(childpid, &status, 0);
+           } while (result == -1 && errno == EINTR);
 #ifndef PERL_MICRO
-             (void)rsignal_restore(SIGINT, &ihand);
-             (void)rsignal_restore(SIGQUIT, &qhand);
-#endif
-             STATUS_NATIVE_SET(result == -1 ? -1 : status);
-             do_execfree();    /* free any memory child malloced on fork */
-             SP = ORIGMARK;
-             if (did_pipes) {
-                  int errkid;
-                  int n = 0, n1;
-               
-                  while (n < sizeof(int)) {
-                       n1 = PerlLIO_read(pp[0],
-                                         (void*)(((char*)&errkid)+n),
-                                         (sizeof(int)) - n);
-                       if (n1 <= 0)
-                            break;
-                       n += n1;
-                  }
-                  PerlLIO_close(pp[0]);
-                  if (n) {                     /* Error */
-                       if (n != sizeof(int))
-                            DIE(aTHX_ "panic: kid popen errno read");
-                       errno = errkid;         /* Propagate errno from kid */
-                       STATUS_CURRENT = -1;
-                  }
-             }
-             PUSHi(STATUS_CURRENT);
-             RETURN;
-        }
-        if (did_pipes) {
-             PerlLIO_close(pp[0]);
+           (void)rsignal_restore(SIGINT, &ihand);
+           (void)rsignal_restore(SIGQUIT, &qhand);
+#endif
+           STATUS_NATIVE_SET(result == -1 ? -1 : status);
+           do_execfree();      /* free any memory child malloced on fork */
+           SP = ORIGMARK;
+           if (did_pipes) {
+               int errkid;
+               int n = 0, n1;
+
+               while (n < sizeof(int)) {
+                   n1 = PerlLIO_read(pp[0],
+                                     (void*)(((char*)&errkid)+n),
+                                     (sizeof(int)) - n);
+                   if (n1 <= 0)
+                       break;
+                   n += n1;
+               }
+               PerlLIO_close(pp[0]);
+               if (n) {                        /* Error */
+                   if (n != sizeof(int))
+                       DIE(aTHX_ "panic: kid popen errno read");
+                   errno = errkid;             /* Propagate errno from kid */
+                   STATUS_CURRENT = -1;
+               }
+           }
+           PUSHi(STATUS_CURRENT);
+           RETURN;
+       }
+       if (did_pipes) {
+           PerlLIO_close(pp[0]);
 #if defined(HAS_FCNTL) && defined(F_SETFD)
-             fcntl(pp[1], F_SETFD, FD_CLOEXEC);
+           fcntl(pp[1], F_SETFD, FD_CLOEXEC);
 #endif
-        }
-    }
-    if (PL_op->op_flags & OPf_STACKED) {
-       SV *really = *++MARK;
-       value = (I32)do_aexec5(really, MARK, SP, pp[1], did_pipes);
-    }
-    else if (SP - MARK != 1)
-       value = (I32)do_aexec5(Nullsv, MARK, SP, pp[1], did_pipes);
-    else {
-       value = (I32)do_exec3(SvPVx(sv_mortalcopy(*SP), n_a), pp[1], did_pipes);
+       }
+       if (PL_op->op_flags & OPf_STACKED) {
+           SV *really = *++MARK;
+           value = (I32)do_aexec5(really, MARK, SP, pp[1], did_pipes);
+       }
+       else if (SP - MARK != 1)
+           value = (I32)do_aexec5(Nullsv, MARK, SP, pp[1], did_pipes);
+       else {
+           value = (I32)do_exec3(SvPVx(sv_mortalcopy(*SP), n_a), pp[1], did_pipes);
+       }
+       PerlProc__exit(-1);
     }
-    PerlProc__exit(-1);
 #else /* ! FORK or VMS or OS/2 */
     PL_statusvalue = 0;
     result = 0;
     if (PL_op->op_flags & OPf_STACKED) {
        SV *really = *++MARK;
+#  ifdef WIN32
+       value = (I32)do_aspawn(really, MARK, SP);
+#  else
        value = (I32)do_aspawn(really, (void **)MARK, (void **)SP);
+#  endif
     }
-    else if (SP - MARK != 1)
+    else if (SP - MARK != 1) {
+#  ifdef WIN32
+       value = (I32)do_aspawn(Nullsv, MARK, SP);
+#  else
        value = (I32)do_aspawn(Nullsv, (void **)MARK, (void **)SP);
+#  endif
+    }
     else {
        value = (I32)do_spawn(SvPVx(sv_mortalcopy(*SP), n_a));
     }
@@ -4163,18 +4186,11 @@ PP(pp_exec)
        TAINT_ENV();
        while (++MARK <= SP) {
            (void)SvPV_nolen(*MARK);      /* stringify for taint check */
-           if (PL_tainted) 
+           if (PL_tainted)
                break;
        }
        MARK = ORIGMARK;
-       /* XXX Remove warning at end of deprecation cycle --RD 2002-02  */
-       if (SP - MARK == 1) {
-           TAINT_PROPER("exec");
-       }
-       else if (ckWARN2(WARN_TAINT, WARN_DEPRECATED)) {
-           Perl_warner(aTHX_ packWARN2(WARN_TAINT, WARN_DEPRECATED),
-               "Use of tainted arguments in %s is deprecated", "exec");
-       }
+       TAINT_PROPER("exec");
     }
     PERL_FLUSHALL_FOR_CHILD;
     if (PL_op->op_flags & OPf_STACKED) {
@@ -4230,7 +4246,11 @@ PP(pp_getppid)
 {
 #ifdef HAS_GETPPID
     dSP; dTARGET;
+#   ifdef THREADS_HAVE_PIDS
+    XPUSHi( PL_ppid );
+#   else
     XPUSHi( getppid() );
+#   endif
     RETURN;
 #else
     DIE(aTHX_ PL_no_func, "getppid");
@@ -4335,26 +4355,6 @@ PP(pp_time)
     RETURN;
 }
 
-/* XXX The POSIX name is CLK_TCK; it is to be preferred
-   to HZ.  Probably.  For now, assume that if the system
-   defines HZ, it does so correctly.  (Will this break
-   on VMS?)
-   Probably we ought to use _sysconf(_SC_CLK_TCK), if
-   it's supported.    --AD  9/96.
-*/
-
-#ifdef __BEOS__
-#  define HZ 1000000
-#endif
-
-#ifndef HZ
-#  ifdef CLK_TCK
-#    define HZ CLK_TCK
-#  else
-#    define HZ 60
-#  endif
-#endif
-
 PP(pp_tms)
 {
 #ifdef HAS_TIMES
@@ -4368,11 +4368,11 @@ PP(pp_tms)
                                                    /* is returned.                   */
 #endif
 
-    PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_utime)/HZ)));
+    PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_utime)/(NV)PL_clocktick)));
     if (GIMME == G_ARRAY) {
-       PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_stime)/HZ)));
-       PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_cutime)/HZ)));
-       PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_cstime)/HZ)));
+       PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_stime)/(NV)PL_clocktick)));
+       PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_cutime)/(NV)PL_clocktick)));
+       PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_cstime)/(NV)PL_clocktick)));
     }
     RETURN;
 #else
@@ -4950,7 +4950,7 @@ PP(pp_gservent)
     else if (which == OP_GSBYPORT) {
 #ifdef HAS_GETSERVBYPORT
        char *proto = POPpbytex;
-       unsigned short port = POPu;
+       unsigned short port = (unsigned short)POPu;
 
 #ifdef HAS_HTONS
        port = PerlSock_htons(port);
@@ -5197,6 +5197,9 @@ PP(pp_gpwent)
     case OP_GPWENT:
 #   ifdef HAS_GETPWENT
        pwent  = getpwent();
+#ifdef POSIX_BC   /* In some cases pw_passwd has invalid addresses */
+       if (pwent) pwent = getpwnam(pwent->pw_name);
+#endif
 #   else
        DIE(aTHX_ PL_no_func, "getpwent");
 #   endif
@@ -5428,12 +5431,22 @@ PP(pp_ggrent)
        PUSHs(sv = sv_mortalcopy(&PL_sv_no));
        sv_setiv(sv, (IV)grent->gr_gid);
 
+#if !(defined(_CRAYMPP) && defined(USE_REENTRANT_API))
        PUSHs(sv = sv_mortalcopy(&PL_sv_no));
+       /* In UNICOS/mk (_CRAYMPP) the multithreading
+        * versions (getgrnam_r, getgrgid_r)
+        * seem to return an illegal pointer
+        * as the group members list, gr_mem.
+        * getgrent() doesn't even have a _r version
+        * but the gr_mem is poisonous anyway.
+        * So yes, you cannot get the list of group
+        * members if building multithreaded in UNICOS/mk. */
        for (elem = grent->gr_mem; elem && *elem; elem++) {
            sv_catpv(sv, *elem);
            if (elem[1])
                sv_catpvn(sv, " ", 1);
        }
+#endif
     }
 
     RETURN;