X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pp_sys.c;h=40628afcdb4fadf1c7334361334eadd143ca1701;hb=4beedc23b598a493399ba23c8c4bd5448e52283a;hp=57e4099bb1b5d1bbfa4eab0d6bb2e16acaae165e;hpb=e5c9fcd0420f2862565625a4bd5596204107f54f;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pp_sys.c b/pp_sys.c index 57e4099..40628af 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -54,7 +54,11 @@ extern "C" int syscall(unsigned long,...); #endif #endif -#ifdef HOST_NOT_FOUND +/* XXX Configure test needed. + h_errno might not be a simple 'int', especially for multi-threaded + applications. HOST_NOT_FOUND is typically defined in . +*/ +#if defined(HOST_NOT_FOUND) && !defined(h_errno) extern int h_errno; #endif @@ -65,7 +69,9 @@ extern int h_errno; struct passwd *getpwnam _((char *)); struct passwd *getpwuid _((Uid_t)); # endif +# ifdef HAS_GETPWENT struct passwd *getpwent _((void)); +# endif #endif #ifdef HAS_GROUP @@ -75,7 +81,9 @@ extern int h_errno; struct group *getgrnam _((char *)); struct group *getgrgid _((Gid_t)); # endif +# ifdef HAS_GETGRENT struct group *getgrent _((void)); +# endif #endif #ifdef I_UTIME @@ -203,7 +211,7 @@ PP(pp_backtick) SV *sv; for (;;) { - sv = NEWSV(56, 80); + sv = NEWSV(56, 79); if (sv_gets(sv, fp, 0) == Nullch) { SvREFCNT_dec(sv); break; @@ -234,7 +242,7 @@ PP(pp_glob) ENTER; #ifndef VMS - if (tainting) { + if (PL_tainting) { /* * The external globbing program may use things we can't control, * so for security reasons we must assume the worst. @@ -244,14 +252,14 @@ PP(pp_glob) } #endif /* !VMS */ - SAVESPTR(last_in_gv); /* We don't want this to be permanent. */ - last_in_gv = (GV*)*stack_sp--; + SAVESPTR(PL_last_in_gv); /* We don't want this to be permanent. */ + PL_last_in_gv = (GV*)*PL_stack_sp--; - SAVESPTR(rs); /* This is not permanent, either. */ - rs = sv_2mortal(newSVpv("", 1)); + SAVESPTR(PL_rs); /* This is not permanent, either. */ + PL_rs = sv_2mortal(newSVpv("", 1)); #ifndef DOSISH #ifndef CSH - *SvPVX(rs) = '\n'; + *SvPVX(PL_rs) = '\n'; #endif /* !CSH */ #endif /* !DOSISH */ @@ -260,15 +268,17 @@ PP(pp_glob) return result; } +#if 0 /* XXX never used! */ PP(pp_indread) { - last_in_gv = gv_fetchpv(SvPVx(GvSV((GV*)(*stack_sp--)), na), TRUE,SVt_PVIO); + PL_last_in_gv = gv_fetchpv(SvPVx(GvSV((GV*)(*PL_stack_sp--)), PL_na), TRUE,SVt_PVIO); return do_readline(); } +#endif PP(pp_rcatline) { - last_in_gv = cGVOP->op_gv; + PL_last_in_gv = cGVOP->op_gv; return do_readline(); } @@ -278,18 +288,19 @@ PP(pp_warn) char *tmps; if (SP - MARK != 1) { dTARGET; - do_join(TARG, &sv_no, MARK, SP); - tmps = SvPV(TARG, na); + do_join(TARG, &PL_sv_no, MARK, SP); + tmps = SvPV(TARG, PL_na); SP = MARK + 1; } else { - tmps = SvPV(TOPs, na); + tmps = SvPV(TOPs, PL_na); } if (!tmps || !*tmps) { - (void)SvUPGRADE(ERRSV, SVt_PV); - if (SvPOK(ERRSV) && SvCUR(ERRSV)) - sv_catpv(ERRSV, "\t...caught"); - tmps = SvPV(ERRSV, na); + SV *error = ERRSV; + (void)SvUPGRADE(error, SVt_PV); + if (SvPOK(error) && SvCUR(error)) + sv_catpv(error, "\t...caught"); + tmps = SvPV(error, PL_na); } if (!tmps || !*tmps) tmps = "Warning: something's wrong"; @@ -301,24 +312,52 @@ PP(pp_die) { djSP; dMARK; char *tmps; + SV *tmpsv = Nullsv; + char *pat = "%s"; if (SP - MARK != 1) { dTARGET; - do_join(TARG, &sv_no, MARK, SP); - tmps = SvPV(TARG, na); + do_join(TARG, &PL_sv_no, MARK, SP); + tmps = SvPV(TARG, PL_na); SP = MARK + 1; } else { - tmps = SvPV(TOPs, na); + tmpsv = TOPs; + tmps = SvROK(tmpsv) ? Nullch : SvPV(tmpsv, PL_na); } if (!tmps || !*tmps) { - (void)SvUPGRADE(ERRSV, SVt_PV); - if (SvPOK(ERRSV) && SvCUR(ERRSV)) - sv_catpv(ERRSV, "\t...propagated"); - tmps = SvPV(ERRSV, na); + SV *error = ERRSV; + (void)SvUPGRADE(error, SVt_PV); + if(tmpsv ? SvROK(tmpsv) : SvROK(error)) { + if(tmpsv) + SvSetSV(error,tmpsv); + else if(sv_isobject(error)) { + HV *stash = SvSTASH(SvRV(error)); + GV *gv = gv_fetchmethod(stash, "PROPAGATE"); + if (gv) { + SV *file = sv_2mortal(newSVsv(GvSV(PL_curcop->cop_filegv))); + SV *line = sv_2mortal(newSViv(PL_curcop->cop_line)); + EXTEND(SP, 3); + PUSHMARK(SP); + PUSHs(error); + PUSHs(file); + PUSHs(line); + PUTBACK; + perl_call_sv((SV*)GvCV(gv), + G_SCALAR|G_EVAL|G_KEEPERR); + sv_setsv(error,*PL_stack_sp--); + } + } + pat = Nullch; + } + else { + if (SvPOK(error) && SvCUR(error)) + sv_catpv(error, "\t...propagated"); + tmps = SvPV(error, PL_na); + } } if (!tmps || !*tmps) tmps = "Died"; - DIE("%s", tmps); + DIE(pat, tmps); } /* I/O. */ @@ -343,9 +382,9 @@ PP(pp_open) if (GvIOp(gv)) IoFLAGS(GvIOp(gv)) &= ~IOf_UNTAINT; tmps = SvPV(sv, len); - if (do_open(gv, tmps, len, FALSE, 0, 0, Nullfp)) - PUSHi( (I32)forkprocess ); - else if (forkprocess == 0) /* we are a new child */ + if (do_open(gv, tmps, len, FALSE, O_RDONLY, 0, Nullfp)) + PUSHi( (I32)PL_forkprocess ); + else if (PL_forkprocess == 0) /* we are a new child */ PUSHi(0); else RETPUSHUNDEF; @@ -359,7 +398,7 @@ PP(pp_close) MAGIC *mg; if (MAXARG == 0) - gv = defoutgv; + gv = PL_defoutgv; else gv = (GV*)POPs; @@ -460,7 +499,12 @@ PP(pp_umask) TAINT_PROPER("umask"); XPUSHi(anum); #else - DIE(no_func, "Unsupported function umask"); + /* Only DIE if trying to restrict permissions on `user' (self). + * Otherwise it's harmless and more useful to just return undef + * since 'group' and 'other' concepts probably don't exist here. */ + if (MAXARG >= 1 && (POPi & 0700)) + DIE("umask not implemented"); + XPUSHs(&PL_sv_undef); #endif RETURN; } @@ -481,56 +525,27 @@ PP(pp_binmode) if (!(io = GvIO(gv)) || !(fp = IoIFP(io))) RETPUSHUNDEF; -#ifdef DOSISH -#ifdef atarist - if (!PerlIO_flush(fp) && (fp->_flag |= _IOBIN)) + if (do_binmode(fp,IoTYPE(io),TRUE)) RETPUSHYES; else RETPUSHUNDEF; -#else - if (PerlLIO_setmode(PerlIO_fileno(fp), OP_BINARY) != -1) { -#if defined(WIN32) && defined(__BORLANDC__) - /* The translation mode of the stream is maintained independent - * of the translation mode of the fd in the Borland RTL (heavy - * digging through their runtime sources reveal). User has to - * set the mode explicitly for the stream (though they don't - * document this anywhere). GSAR 97-5-24 - */ - PerlIO_seek(fp,0L,0); - fp->flags |= _F_BIN; -#endif - RETPUSHYES; - } - else - RETPUSHUNDEF; -#endif -#else -#if defined(USEMYBINMODE) - if (my_binmode(fp,IoTYPE(io)) != NULL) - RETPUSHYES; - else - RETPUSHUNDEF; -#else - RETPUSHYES; -#endif -#endif - } PP(pp_tie) { djSP; + dMARK; SV *varsv; HV* stash; GV *gv; SV *sv; - SV **mark = stack_base + ++*markstack_ptr; /* reuse in entersub */ - I32 markoff = mark - stack_base - 1; + I32 markoff = MARK - PL_stack_base; char *methname; int how = 'P'; + U32 items; - varsv = mark[0]; + varsv = *++MARK; switch(SvTYPE(varsv)) { case SVt_PVHV: methname = "TIEHASH"; @@ -547,32 +562,45 @@ PP(pp_tie) how = 'q'; break; } - - if (sv_isobject(mark[1])) { + items = SP - MARK++; + if (sv_isobject(*MARK)) { ENTER; + PUSHSTACKi(PERLSI_MAGIC); + PUSHMARK(SP); + EXTEND(SP,items); + while (items--) + PUSHs(*MARK++); + PUTBACK; perl_call_method(methname, G_SCALAR); } else { /* Not clear why we don't call perl_call_method here too. * perhaps to get different error message ? */ - stash = gv_stashsv(mark[1], FALSE); + stash = gv_stashsv(*MARK, FALSE); if (!stash || !(gv = gv_fetchmethod(stash, methname))) { DIE("Can't locate object method \"%s\" via package \"%s\"", - methname, SvPV(mark[1],na)); + methname, SvPV(*MARK,PL_na)); } ENTER; + PUSHSTACKi(PERLSI_MAGIC); + PUSHMARK(SP); + EXTEND(SP,items); + while (items--) + PUSHs(*MARK++); + PUTBACK; perl_call_sv((SV*)GvCV(gv), G_SCALAR); } SPAGAIN; sv = TOPs; + POPSTACK; if (sv_isobject(sv)) { sv_unmagic(varsv, how); sv_magic(varsv, sv, how, Nullch, 0); } LEAVE; - SP = stack_base + markoff; + SP = PL_stack_base + markoff; PUSHs(sv); RETURN; } @@ -581,9 +609,10 @@ PP(pp_untie) { djSP; SV * sv ; - sv = POPs; - if (dowarn) { + sv = POPs; + + if (ckWARN(WARN_UNTIE)) { MAGIC * mg ; if (SvMAGICAL(sv)) { if (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV) @@ -592,8 +621,9 @@ PP(pp_untie) mg = mg_find(sv, 'q') ; if (mg && SvREFCNT(SvRV(mg->mg_obj)) > 1) - warn("untie attempted while %lu inner references still exist", - (unsigned long)SvREFCNT(SvRV(mg->mg_obj)) - 1 ) ; + warner(WARN_UNTIE, + "untie attempted while %lu inner references still exist", + (unsigned long)SvREFCNT(SvRV(mg->mg_obj)) - 1 ) ; } } @@ -636,7 +666,7 @@ PP(pp_dbmopen) hv = (HV*)POPs; - sv = sv_mortalcopy(&sv_no); + sv = sv_mortalcopy(&PL_sv_no); sv_setpv(sv, "AnyDBM_File"); stash = gv_stashsv(sv, FALSE); if (!stash || !(gv = gv_fetchmethod(stash, "TIEHASH"))) { @@ -648,9 +678,9 @@ PP(pp_dbmopen) } ENTER; - PUSHMARK(sp); + PUSHMARK(SP); - EXTEND(sp, 5); + EXTEND(SP, 5); PUSHs(sv); PUSHs(left); if (SvIV(right)) @@ -663,8 +693,8 @@ PP(pp_dbmopen) SPAGAIN; if (!sv_isobject(TOPs)) { - sp--; - PUSHMARK(sp); + SP--; + PUSHMARK(SP); PUSHs(sv); PUSHs(left); PUSHs(sv_2mortal(newSViv(O_RDONLY))); @@ -725,7 +755,8 @@ PP(pp_sselect) } #if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678 -#if defined(__linux__) || defined(OS2) +/* XXX Configure test needed. */ +#if defined(__linux__) || defined(OS2) || defined(NeXT) || defined(__osf__) || defined(sun) growsize = sizeof(fd_set); #else growsize = maxlen; /* little endians can use vecs directly */ @@ -764,7 +795,7 @@ PP(pp_sselect) continue; } else if (!SvPOK(sv)) - SvPV_force(sv,na); /* force string conversion */ + SvPV_force(sv,PL_na); /* force string conversion */ j = SvLEN(sv); if (j < growsize) { Sv_Grow(sv, growsize); @@ -812,7 +843,7 @@ PP(pp_sselect) if (GIMME == G_ARRAY && tbuf) { value = (double)(timebuf.tv_sec) + (double)(timebuf.tv_usec) / 1000000.0; - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setnv(sv, value); } RETURN; @@ -827,9 +858,9 @@ setdefout(GV *gv) dTHR; if (gv) (void)SvREFCNT_inc(gv); - if (defoutgv) - SvREFCNT_dec(defoutgv); - defoutgv = gv; + if (PL_defoutgv) + SvREFCNT_dec(PL_defoutgv); + PL_defoutgv = gv; } PP(pp_select) @@ -838,18 +869,18 @@ PP(pp_select) GV *newdefout, *egv; HV *hv; - newdefout = (op->op_private > 0) ? ((GV *) POPs) : (GV *) NULL; + newdefout = (PL_op->op_private > 0) ? ((GV *) POPs) : (GV *) NULL; - egv = GvEGV(defoutgv); + egv = GvEGV(PL_defoutgv); if (!egv) - egv = defoutgv; + egv = PL_defoutgv; hv = GvSTASH(egv); if (! hv) - XPUSHs(&sv_undef); + XPUSHs(&PL_sv_undef); else { GV **gvp = (GV**)hv_fetch(hv, GvNAME(egv), GvNAMELEN(egv), FALSE); if (gvp && *gvp == egv) { - gv_efullname3(TARG, defoutgv, Nullch); + gv_efullname3(TARG, PL_defoutgv, Nullch); XPUSHTARG; } else { @@ -873,11 +904,11 @@ PP(pp_getc) MAGIC *mg; if (MAXARG <= 0) - gv = stdingv; + gv = PL_stdingv; else gv = (GV*)POPs; if (!gv) - gv = argvgv; + gv = PL_argvgv; if (SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) { I32 gimme = GIMME_V; @@ -906,7 +937,7 @@ PP(pp_read) return pp_sysread(ARGS); } -static OP * +STATIC OP * doform(CV *cv, GV *gv, OP *retop) { dTHR; @@ -919,10 +950,10 @@ doform(CV *cv, GV *gv, OP *retop) SAVETMPS; push_return(retop); - PUSHBLOCK(cx, CXt_SUB, stack_sp); + PUSHBLOCK(cx, CXt_SUB, PL_stack_sp); PUSHFORMAT(cx); - SAVESPTR(curpad); - curpad = AvARRAY((AV*)svp[1]); + SAVESPTR(PL_curpad); + PL_curpad = AvARRAY((AV*)svp[1]); setdefout(gv); /* locally select filehandle so $% et al work */ return CvSTART(cv); @@ -937,11 +968,11 @@ PP(pp_enterwrite) CV *cv; if (MAXARG == 0) - gv = defoutgv; + gv = PL_defoutgv; else { gv = (GV*)POPs; if (!gv) - gv = defoutgv; + gv = PL_defoutgv; } EXTEND(SP, 1); io = GvIO(gv); @@ -966,7 +997,7 @@ PP(pp_enterwrite) cv = (CV*)sv_2mortal((SV*)cv_clone(cv)); IoFLAGS(io) &= ~IOf_DIDTOP; - return doform(cv,gv,op->op_next); + return doform(cv,gv,PL_op->op_next); } PP(pp_leavewrite) @@ -981,9 +1012,9 @@ PP(pp_leavewrite) register PERL_CONTEXT *cx; DEBUG_f(PerlIO_printf(Perl_debug_log, "left=%ld, todo=%ld\n", - (long)IoLINES_LEFT(io), (long)FmLINES(formtarget))); - if (IoLINES_LEFT(io) < FmLINES(formtarget) && - formtarget != toptarget) + (long)IoLINES_LEFT(io), (long)FmLINES(PL_formtarget))); + if (IoLINES_LEFT(io) < FmLINES(PL_formtarget) && + PL_formtarget != PL_toptarget) { GV *fgv; CV *cv; @@ -1011,7 +1042,7 @@ PP(pp_leavewrite) } if (IoFLAGS(io) & IOf_DIDTOP) { /* Oh dear. It still doesn't fit. */ I32 lines = IoLINES_LEFT(io); - char *s = SvPVX(formtarget); + char *s = SvPVX(PL_formtarget); if (lines <= 0) /* Yow, header didn't even fit!!! */ goto forget_top; while (lines-- > 0) { @@ -1021,16 +1052,16 @@ PP(pp_leavewrite) s++; } if (s) { - PerlIO_write(ofp, SvPVX(formtarget), s - SvPVX(formtarget)); - sv_chop(formtarget, s); - FmLINES(formtarget) -= IoLINES_LEFT(io); + PerlIO_write(ofp, SvPVX(PL_formtarget), s - SvPVX(PL_formtarget)); + sv_chop(PL_formtarget, s); + FmLINES(PL_formtarget) -= IoLINES_LEFT(io); } } if (IoLINES_LEFT(io) >= 0 && IoPAGE(io) > 0) - PerlIO_write(ofp, SvPVX(formfeed), SvCUR(formfeed)); + PerlIO_write(ofp, SvPVX(PL_formfeed), SvCUR(PL_formfeed)); IoLINES_LEFT(io) = IoPAGE_LEN(io); IoPAGE(io)++; - formtarget = toptarget; + PL_formtarget = PL_toptarget; IoFLAGS(io) |= IOf_DIDTOP; fgv = IoTOP_GV(io); if (!fgv) @@ -1043,42 +1074,42 @@ PP(pp_leavewrite) } if (CvCLONE(cv)) cv = (CV*)sv_2mortal((SV*)cv_clone(cv)); - return doform(cv,gv,op); + return doform(cv,gv,PL_op); } forget_top: - POPBLOCK(cx,curpm); + POPBLOCK(cx,PL_curpm); POPFORMAT(cx); LEAVE; fp = IoOFP(io); if (!fp) { - if (dowarn) { + if (ckWARN2(WARN_CLOSED,WARN_IO)) { if (IoIFP(io)) - warn("Filehandle only opened for input"); - else - warn("Write on closed filehandle"); + warner(WARN_IO, "Filehandle only opened for input"); + else if (ckWARN(WARN_CLOSED)) + warner(WARN_CLOSED, "Write on closed filehandle"); } - PUSHs(&sv_no); + PUSHs(&PL_sv_no); } else { - if ((IoLINES_LEFT(io) -= FmLINES(formtarget)) < 0) { - if (dowarn) - warn("page overflow"); + if ((IoLINES_LEFT(io) -= FmLINES(PL_formtarget)) < 0) { + if (ckWARN(WARN_IO)) + warner(WARN_IO, "page overflow"); } - if (!PerlIO_write(ofp, SvPVX(formtarget), SvCUR(formtarget)) || + if (!PerlIO_write(ofp, SvPVX(PL_formtarget), SvCUR(PL_formtarget)) || PerlIO_error(fp)) - PUSHs(&sv_no); + PUSHs(&PL_sv_no); else { - FmLINES(formtarget) = 0; - SvCUR_set(formtarget, 0); - *SvEND(formtarget) = '\0'; + FmLINES(PL_formtarget) = 0; + SvCUR_set(PL_formtarget, 0); + *SvEND(PL_formtarget) = '\0'; if (IoFLAGS(io) & IOf_FLUSH) (void)PerlIO_flush(fp); - PUSHs(&sv_yes); + PUSHs(&PL_sv_yes); } } - formtarget = bodytarget; + PL_formtarget = PL_bodytarget; PUTBACK; return pop_return(); } @@ -1092,10 +1123,10 @@ PP(pp_prtf) SV *sv; MAGIC *mg; - if (op->op_flags & OPf_STACKED) + if (PL_op->op_flags & OPf_STACKED) gv = (GV*)*++MARK; else - gv = defoutgv; + gv = PL_defoutgv; if (SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) { if (MARK == ORIGMARK) { @@ -1119,27 +1150,29 @@ PP(pp_prtf) sv = NEWSV(0,0); if (!(io = GvIO(gv))) { - if (dowarn) { + if (ckWARN(WARN_UNOPENED)) { gv_fullname3(sv, gv, Nullch); - warn("Filehandle %s never opened", SvPV(sv,na)); + warner(WARN_UNOPENED, "Filehandle %s never opened", SvPV(sv,PL_na)); } SETERRNO(EBADF,RMS$_IFI); goto just_say_no; } else if (!(fp = IoOFP(io))) { - if (dowarn) { + if (ckWARN2(WARN_CLOSED,WARN_IO)) { gv_fullname3(sv, gv, Nullch); if (IoIFP(io)) - warn("Filehandle %s opened only for input", SvPV(sv,na)); - else - warn("printf on closed filehandle %s", SvPV(sv,na)); + warner(WARN_IO, "Filehandle %s opened only for input", + SvPV(sv,PL_na)); + else if (ckWARN(WARN_CLOSED)) + warner(WARN_CLOSED, "printf on closed filehandle %s", + SvPV(sv,PL_na)); } SETERRNO(EBADF,IoIFP(io)?RMS$_FAC:RMS$_IFI); goto just_say_no; } else { #ifdef USE_LOCALE_NUMERIC - if (op->op_private & OPpLOCALE) + if (PL_op->op_private & OPpLOCALE) SET_NUMERIC_LOCAL(); else SET_NUMERIC_STANDARD(); @@ -1154,13 +1187,13 @@ PP(pp_prtf) } SvREFCNT_dec(sv); SP = ORIGMARK; - PUSHs(&sv_yes); + PUSHs(&PL_sv_yes); RETURN; just_say_no: SvREFCNT_dec(sv); SP = ORIGMARK; - PUSHs(&sv_undef); + PUSHs(&PL_sv_undef); RETURN; } @@ -1184,10 +1217,10 @@ PP(pp_sysopen) tmps = SvPV(sv, len); if (do_open(gv, tmps, len, TRUE, mode, perm, Nullfp)) { IoLINES(GvIOp(gv)) = 0; - PUSHs(&sv_yes); + PUSHs(&PL_sv_yes); } else { - PUSHs(&sv_undef); + PUSHs(&PL_sv_undef); } RETURN; } @@ -1206,7 +1239,7 @@ PP(pp_sysread) MAGIC *mg; gv = (GV*)*++MARK; - if ((op->op_type == OP_READ || op->op_type == OP_SYSREAD) && + if ((PL_op->op_type == OP_READ || PL_op->op_type == OP_SYSREAD) && SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) { SV *sv; @@ -1241,9 +1274,9 @@ PP(pp_sysread) if (!io || !IoIFP(io)) goto say_undef; #ifdef HAS_SOCKET - if (op->op_type == OP_RECV) { + if (PL_op->op_type == OP_RECV) { char namebuf[MAXPATHLEN]; -#if defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS) +#if (defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS)) || defined(MPE) bufsize = sizeof (struct sockaddr_in); #else bufsize = sizeof namebuf; @@ -1267,7 +1300,7 @@ PP(pp_sysread) RETURN; } #else - if (op->op_type == OP_RECV) + if (PL_op->op_type == OP_RECV) DIE(no_sock_func, "recv"); #endif if (offset < 0) { @@ -1280,7 +1313,7 @@ PP(pp_sysread) if (offset > bufsize) { /* Zero any newly allocated space */ Zero(buffer+bufsize, offset-bufsize, char); } - if (op->op_type == OP_SYSREAD) { + if (PL_op->op_type == OP_SYSREAD) { length = PerlLIO_read(PerlIO_fileno(IoIFP(io)), buffer+offset, length); } else @@ -1297,7 +1330,12 @@ PP(pp_sysread) } else #endif + { length = PerlIO_read(IoIFP(io), buffer+offset, length); + /* fread() returns 0 on both error and EOF */ + if (length == 0 && PerlIO_error(IoIFP(io))) + length = -1; + } if (length < 0) goto say_undef; SvCUR_set(bufsv, length+offset); @@ -1334,7 +1372,7 @@ PP(pp_send) MAGIC *mg; gv = (GV*)*++MARK; - if (op->op_type == OP_SYSWRITE && + if (PL_op->op_type == OP_SYSWRITE && SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) { SV *sv; @@ -1361,14 +1399,14 @@ PP(pp_send) io = GvIO(gv); if (!io || !IoIFP(io)) { length = -1; - if (dowarn) { - if (op->op_type == OP_SYSWRITE) - warn("Syswrite on closed filehandle"); + if (ckWARN(WARN_CLOSED)) { + if (PL_op->op_type == OP_SYSWRITE) + warner(WARN_CLOSED, "Syswrite on closed filehandle"); else - warn("Send on closed socket"); + warner(WARN_CLOSED, "Send on closed socket"); } } - else if (op->op_type == OP_SYSWRITE) { + else if (PL_op->op_type == OP_SYSWRITE) { if (MARK < SP) { offset = SvIVx(*++MARK); if (offset < 0) { @@ -1420,9 +1458,9 @@ PP(pp_eof) GV *gv; if (MAXARG <= 0) - gv = last_in_gv; + gv = PL_last_in_gv; else - gv = last_in_gv = (GV*)POPs; + gv = PL_last_in_gv = (GV*)POPs; PUSHs(boolSV(!gv || do_eof(gv))); RETURN; } @@ -1433,9 +1471,9 @@ PP(pp_tell) GV *gv; if (MAXARG <= 0) - gv = last_in_gv; + gv = PL_last_in_gv; else - gv = last_in_gv = (GV*)POPs; + gv = PL_last_in_gv = (GV*)POPs; PUSHi( do_tell(gv) ); RETURN; } @@ -1452,12 +1490,12 @@ PP(pp_sysseek) int whence = POPi; long offset = POPl; - gv = last_in_gv = (GV*)POPs; - if (op->op_type == OP_SEEK) + gv = PL_last_in_gv = (GV*)POPs; + if (PL_op->op_type == OP_SEEK) PUSHs(boolSV(do_seek(gv, offset, whence))); else { long n = do_sysseek(gv, offset, whence); - PUSHs((n < 0) ? &sv_undef + PUSHs((n < 0) ? &PL_sv_undef : sv_2mortal(n ? newSViv((IV)n) : newSVpv(zero_but_true, ZBTLEN))); } @@ -1473,7 +1511,7 @@ PP(pp_truncate) SETERRNO(0,0); #if defined(HAS_TRUNCATE) || defined(HAS_CHSIZE) || defined(F_FREESP) - if (op->op_flags & OPf_SPECIAL) { + if (PL_op->op_flags & OPf_SPECIAL) { tmpgv = gv_fetchpv(POPp, FALSE, SVt_PVIO); do_ftruncate: TAINT_PROPER("truncate"); @@ -1498,7 +1536,7 @@ PP(pp_truncate) goto do_ftruncate; } - name = SvPV(sv, na); + name = SvPV(sv, PL_na); TAINT_PROPER("truncate"); #ifdef HAS_TRUNCATE if (truncate(name, len) < 0) @@ -1537,7 +1575,7 @@ PP(pp_ioctl) djSP; dTARGET; SV *argsv = POPs; unsigned int func = U_I(POPn); - int optype = op->op_type; + int optype = PL_op->op_type; char *s; IV retval; GV *gv = (GV*)POPs; @@ -1569,7 +1607,7 @@ PP(pp_ioctl) if (optype == OP_IOCTL) #ifdef HAS_IOCTL - retval = ioctl(PerlIO_fileno(IoIFP(io)), func, s); + retval = PerlLIO_ioctl(PerlIO_fileno(IoIFP(io)), func, s); #else DIE("ioctl is not implemented"); #endif @@ -1614,7 +1652,7 @@ PP(pp_flock) #ifdef FLOCK argtype = POPi; if (MAXARG <= 0) - gv = last_in_gv; + gv = PL_last_in_gv; else gv = (GV*)POPs; if (gv && GvIO(gv)) @@ -1623,7 +1661,7 @@ PP(pp_flock) fp = Nullfp; if (fp) { (void)PerlIO_flush(fp); - value = (I32)(FLOCK(PerlIO_fileno(fp), argtype) >= 0); + value = (I32)(PerlLIO_flock(PerlIO_fileno(fp), argtype) >= 0); } else value = 0; @@ -1732,25 +1770,54 @@ PP(pp_bind) { djSP; #ifdef HAS_SOCKET +#ifdef MPE /* Requires PRIV mode to bind() to ports < 1024 */ + extern GETPRIVMODE(); + extern GETUSERMODE(); +#endif SV *addrsv = POPs; char *addr; GV *gv = (GV*)POPs; register IO *io = GvIOn(gv); STRLEN len; + int bind_ok = 0; +#ifdef MPE + int mpeprivmode = 0; +#endif if (!io || !IoIFP(io)) goto nuts; addr = SvPV(addrsv, len); TAINT_PROPER("bind"); - if (PerlSock_bind(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0) +#ifdef MPE /* Deal with MPE bind() peculiarities */ + if (((struct sockaddr *)addr)->sa_family == AF_INET) { + /* The address *MUST* stupidly be zero. */ + ((struct sockaddr_in *)addr)->sin_addr.s_addr = INADDR_ANY; + /* PRIV mode is required to bind() to ports < 1024. */ + if (((struct sockaddr_in *)addr)->sin_port < 1024 && + ((struct sockaddr_in *)addr)->sin_port > 0) { + GETPRIVMODE(); /* If this fails, we are aborted by MPE/iX. */ + mpeprivmode = 1; + } + } +#endif /* MPE */ + if (PerlSock_bind(PerlIO_fileno(IoIFP(io)), + (struct sockaddr *)addr, len) >= 0) + bind_ok = 1; + +#ifdef MPE /* Switch back to USER mode */ + if (mpeprivmode) + GETUSERMODE(); +#endif /* MPE */ + + if (bind_ok) RETPUSHYES; else RETPUSHUNDEF; nuts: - if (dowarn) - warn("bind() on closed fd"); + if (ckWARN(WARN_CLOSED)) + warner(WARN_CLOSED, "bind() on closed fd"); SETERRNO(EBADF,SS$_IVCHAN); RETPUSHUNDEF; #else @@ -1779,8 +1846,8 @@ PP(pp_connect) RETPUSHUNDEF; nuts: - if (dowarn) - warn("connect() on closed fd"); + if (ckWARN(WARN_CLOSED)) + warner(WARN_CLOSED, "connect() on closed fd"); SETERRNO(EBADF,SS$_IVCHAN); RETPUSHUNDEF; #else @@ -1805,8 +1872,8 @@ PP(pp_listen) RETPUSHUNDEF; nuts: - if (dowarn) - warn("listen() on closed fd"); + if (ckWARN(WARN_CLOSED)) + warner(WARN_CLOSED, "listen() on closed fd"); SETERRNO(EBADF,SS$_IVCHAN); RETPUSHUNDEF; #else @@ -1859,8 +1926,8 @@ PP(pp_accept) RETURN; nuts: - if (dowarn) - warn("accept() on closed fd"); + if (ckWARN(WARN_CLOSED)) + warner(WARN_CLOSED, "accept() on closed fd"); SETERRNO(EBADF,SS$_IVCHAN); badexit: @@ -1886,8 +1953,8 @@ PP(pp_shutdown) RETURN; nuts: - if (dowarn) - warn("shutdown() on closed fd"); + if (ckWARN(WARN_CLOSED)) + warner(WARN_CLOSED, "shutdown() on closed fd"); SETERRNO(EBADF,SS$_IVCHAN); RETPUSHUNDEF; #else @@ -1908,7 +1975,7 @@ PP(pp_ssockopt) { djSP; #ifdef HAS_SOCKET - int optype = op->op_type; + int optype = PL_op->op_type; SV *sv; int fd; unsigned int optname; @@ -1947,25 +2014,25 @@ PP(pp_ssockopt) char *buf; int aint; if (SvPOKp(sv)) { - buf = SvPV(sv, na); - len = na; + buf = SvPV(sv, PL_na); + len = PL_na; } - else if (SvOK(sv)) { + else { aint = (int)SvIV(sv); buf = (char*)&aint; len = sizeof(int); } if (PerlSock_setsockopt(fd, lvl, optname, buf, len) < 0) goto nuts2; - PUSHs(&sv_yes); + PUSHs(&PL_sv_yes); } break; } RETURN; nuts: - if (dowarn) - warn("[gs]etsockopt() on closed fd"); + if (ckWARN(WARN_CLOSED)) + warner(WARN_CLOSED, "[gs]etsockopt() on closed fd"); SETERRNO(EBADF,SS$_IVCHAN); nuts2: RETPUSHUNDEF; @@ -1988,7 +2055,7 @@ PP(pp_getpeername) { djSP; #ifdef HAS_SOCKET - int optype = op->op_type; + int optype = PL_op->op_type; SV *sv; int fd; GV *gv = (GV*)POPs; @@ -2037,8 +2104,8 @@ PP(pp_getpeername) RETURN; nuts: - if (dowarn) - warn("get{sock, peer}name() on closed fd"); + if (ckWARN(WARN_CLOSED)) + warner(WARN_CLOSED, "get{sock, peer}name() on closed fd"); SETERRNO(EBADF,SS$_IVCHAN); nuts2: RETPUSHUNDEF; @@ -2062,17 +2129,17 @@ PP(pp_stat) I32 gimme; I32 max = 13; - if (op->op_flags & OPf_REF) { + if (PL_op->op_flags & OPf_REF) { tmpgv = cGVOP->op_gv; do_fstat: - if (tmpgv != defgv) { - laststype = OP_STAT; - statgv = tmpgv; - sv_setpv(statname, ""); - laststatval = (GvIO(tmpgv) && IoIFP(GvIOp(tmpgv)) - ? PerlLIO_fstat(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), &statcache) : -1); + if (tmpgv != PL_defgv) { + PL_laststype = OP_STAT; + PL_statgv = tmpgv; + sv_setpv(PL_statname, ""); + PL_laststatval = (GvIO(tmpgv) && IoIFP(GvIOp(tmpgv)) + ? PerlLIO_fstat(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), &PL_statcache) : -1); } - if (laststatval < 0) + if (PL_laststatval < 0) max = 0; } else { @@ -2085,18 +2152,18 @@ PP(pp_stat) tmpgv = (GV*)SvRV(sv); goto do_fstat; } - sv_setpv(statname, SvPV(sv,na)); - statgv = Nullgv; + sv_setpv(PL_statname, SvPV(sv,PL_na)); + PL_statgv = Nullgv; #ifdef HAS_LSTAT - laststype = op->op_type; - if (op->op_type == OP_LSTAT) - laststatval = PerlLIO_lstat(SvPV(statname, na), &statcache); + PL_laststype = PL_op->op_type; + if (PL_op->op_type == OP_LSTAT) + PL_laststatval = PerlLIO_lstat(SvPV(PL_statname, PL_na), &PL_statcache); else #endif - laststatval = Stat(SvPV(statname, na), &statcache); - if (laststatval < 0) { - if (dowarn && strchr(SvPV(statname, na), '\n')) - warn(warn_nl, "stat"); + PL_laststatval = PerlLIO_stat(SvPV(PL_statname, PL_na), &PL_statcache); + if (PL_laststatval < 0) { + if (ckWARN(WARN_NEWLINE) && strchr(SvPV(PL_statname, PL_na), '\n')) + warner(WARN_NEWLINE, warn_nl, "stat"); max = 0; } } @@ -2110,30 +2177,30 @@ PP(pp_stat) if (max) { EXTEND(SP, max); EXTEND_MORTAL(max); - PUSHs(sv_2mortal(newSViv((I32)statcache.st_dev))); - PUSHs(sv_2mortal(newSViv((I32)statcache.st_ino))); - PUSHs(sv_2mortal(newSViv((I32)statcache.st_mode))); - PUSHs(sv_2mortal(newSViv((I32)statcache.st_nlink))); - PUSHs(sv_2mortal(newSViv((I32)statcache.st_uid))); - PUSHs(sv_2mortal(newSViv((I32)statcache.st_gid))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_dev))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_ino))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_mode))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_nlink))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_uid))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_gid))); #ifdef USE_STAT_RDEV - PUSHs(sv_2mortal(newSViv((I32)statcache.st_rdev))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_rdev))); #else PUSHs(sv_2mortal(newSVpv("", 0))); #endif - PUSHs(sv_2mortal(newSViv((I32)statcache.st_size))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_size))); #ifdef BIG_TIME - PUSHs(sv_2mortal(newSVnv((U32)statcache.st_atime))); - PUSHs(sv_2mortal(newSVnv((U32)statcache.st_mtime))); - PUSHs(sv_2mortal(newSVnv((U32)statcache.st_ctime))); + PUSHs(sv_2mortal(newSVnv((U32)PL_statcache.st_atime))); + PUSHs(sv_2mortal(newSVnv((U32)PL_statcache.st_mtime))); + PUSHs(sv_2mortal(newSVnv((U32)PL_statcache.st_ctime))); #else - PUSHs(sv_2mortal(newSViv((I32)statcache.st_atime))); - PUSHs(sv_2mortal(newSViv((I32)statcache.st_mtime))); - PUSHs(sv_2mortal(newSViv((I32)statcache.st_ctime))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_atime))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_mtime))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_ctime))); #endif #ifdef USE_STAT_BLOCKS - PUSHs(sv_2mortal(newSViv((I32)statcache.st_blksize))); - PUSHs(sv_2mortal(newSViv((I32)statcache.st_blocks))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_blksize))); + PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_blocks))); #else PUSHs(sv_2mortal(newSVpv("", 0))); PUSHs(sv_2mortal(newSVpv("", 0))); @@ -2148,7 +2215,7 @@ PP(pp_ftrread) djSP; if (result < 0) RETPUSHUNDEF; - if (cando(S_IRUSR, 0, &statcache)) + if (cando(S_IRUSR, 0, &PL_statcache)) RETPUSHYES; RETPUSHNO; } @@ -2159,7 +2226,7 @@ PP(pp_ftrwrite) djSP; if (result < 0) RETPUSHUNDEF; - if (cando(S_IWUSR, 0, &statcache)) + if (cando(S_IWUSR, 0, &PL_statcache)) RETPUSHYES; RETPUSHNO; } @@ -2170,7 +2237,7 @@ PP(pp_ftrexec) djSP; if (result < 0) RETPUSHUNDEF; - if (cando(S_IXUSR, 0, &statcache)) + if (cando(S_IXUSR, 0, &PL_statcache)) RETPUSHYES; RETPUSHNO; } @@ -2181,7 +2248,7 @@ PP(pp_fteread) djSP; if (result < 0) RETPUSHUNDEF; - if (cando(S_IRUSR, 1, &statcache)) + if (cando(S_IRUSR, 1, &PL_statcache)) RETPUSHYES; RETPUSHNO; } @@ -2192,7 +2259,7 @@ PP(pp_ftewrite) djSP; if (result < 0) RETPUSHUNDEF; - if (cando(S_IWUSR, 1, &statcache)) + if (cando(S_IWUSR, 1, &PL_statcache)) RETPUSHYES; RETPUSHNO; } @@ -2203,7 +2270,7 @@ PP(pp_fteexec) djSP; if (result < 0) RETPUSHUNDEF; - if (cando(S_IXUSR, 1, &statcache)) + if (cando(S_IXUSR, 1, &PL_statcache)) RETPUSHYES; RETPUSHNO; } @@ -2228,7 +2295,7 @@ PP(pp_ftrowned) djSP; if (result < 0) RETPUSHUNDEF; - if (statcache.st_uid == (op->op_type == OP_FTEOWNED ? euid : uid) ) + if (PL_statcache.st_uid == (PL_op->op_type == OP_FTEOWNED ? PL_euid : PL_uid) ) RETPUSHYES; RETPUSHNO; } @@ -2239,7 +2306,7 @@ PP(pp_ftzero) djSP; if (result < 0) RETPUSHUNDEF; - if (!statcache.st_size) + if (!PL_statcache.st_size) RETPUSHYES; RETPUSHNO; } @@ -2250,7 +2317,7 @@ PP(pp_ftsize) djSP; dTARGET; if (result < 0) RETPUSHUNDEF; - PUSHi(statcache.st_size); + PUSHi(PL_statcache.st_size); RETURN; } @@ -2260,7 +2327,7 @@ PP(pp_ftmtime) djSP; dTARGET; if (result < 0) RETPUSHUNDEF; - PUSHn( ((I32)basetime - (I32)statcache.st_mtime) / 86400.0 ); + PUSHn( ((I32)PL_basetime - (I32)PL_statcache.st_mtime) / 86400.0 ); RETURN; } @@ -2270,7 +2337,7 @@ PP(pp_ftatime) djSP; dTARGET; if (result < 0) RETPUSHUNDEF; - PUSHn( ((I32)basetime - (I32)statcache.st_atime) / 86400.0 ); + PUSHn( ((I32)PL_basetime - (I32)PL_statcache.st_atime) / 86400.0 ); RETURN; } @@ -2280,7 +2347,7 @@ PP(pp_ftctime) djSP; dTARGET; if (result < 0) RETPUSHUNDEF; - PUSHn( ((I32)basetime - (I32)statcache.st_ctime) / 86400.0 ); + PUSHn( ((I32)PL_basetime - (I32)PL_statcache.st_ctime) / 86400.0 ); RETURN; } @@ -2290,7 +2357,7 @@ PP(pp_ftsock) djSP; if (result < 0) RETPUSHUNDEF; - if (S_ISSOCK(statcache.st_mode)) + if (S_ISSOCK(PL_statcache.st_mode)) RETPUSHYES; RETPUSHNO; } @@ -2301,7 +2368,7 @@ PP(pp_ftchr) djSP; if (result < 0) RETPUSHUNDEF; - if (S_ISCHR(statcache.st_mode)) + if (S_ISCHR(PL_statcache.st_mode)) RETPUSHYES; RETPUSHNO; } @@ -2312,7 +2379,7 @@ PP(pp_ftblk) djSP; if (result < 0) RETPUSHUNDEF; - if (S_ISBLK(statcache.st_mode)) + if (S_ISBLK(PL_statcache.st_mode)) RETPUSHYES; RETPUSHNO; } @@ -2323,7 +2390,7 @@ PP(pp_ftfile) djSP; if (result < 0) RETPUSHUNDEF; - if (S_ISREG(statcache.st_mode)) + if (S_ISREG(PL_statcache.st_mode)) RETPUSHYES; RETPUSHNO; } @@ -2334,7 +2401,7 @@ PP(pp_ftdir) djSP; if (result < 0) RETPUSHUNDEF; - if (S_ISDIR(statcache.st_mode)) + if (S_ISDIR(PL_statcache.st_mode)) RETPUSHYES; RETPUSHNO; } @@ -2345,7 +2412,7 @@ PP(pp_ftpipe) djSP; if (result < 0) RETPUSHUNDEF; - if (S_ISFIFO(statcache.st_mode)) + if (S_ISFIFO(PL_statcache.st_mode)) RETPUSHYES; RETPUSHNO; } @@ -2356,7 +2423,7 @@ PP(pp_ftlink) djSP; if (result < 0) RETPUSHUNDEF; - if (S_ISLNK(statcache.st_mode)) + if (S_ISLNK(PL_statcache.st_mode)) RETPUSHYES; RETPUSHNO; } @@ -2369,7 +2436,7 @@ PP(pp_ftsuid) SPAGAIN; if (result < 0) RETPUSHUNDEF; - if (statcache.st_mode & S_ISUID) + if (PL_statcache.st_mode & S_ISUID) RETPUSHYES; #endif RETPUSHNO; @@ -2383,7 +2450,7 @@ PP(pp_ftsgid) SPAGAIN; if (result < 0) RETPUSHUNDEF; - if (statcache.st_mode & S_ISGID) + if (PL_statcache.st_mode & S_ISGID) RETPUSHYES; #endif RETPUSHNO; @@ -2397,7 +2464,7 @@ PP(pp_ftsvtx) SPAGAIN; if (result < 0) RETPUSHUNDEF; - if (statcache.st_mode & S_ISVTX) + if (PL_statcache.st_mode & S_ISVTX) RETPUSHYES; #endif RETPUSHNO; @@ -2410,7 +2477,7 @@ PP(pp_fttty) GV *gv; char *tmps = Nullch; - if (op->op_flags & OPf_REF) + if (PL_op->op_flags & OPf_REF) gv = cGVOP->op_gv; else if (isGV(TOPs)) gv = (GV*)POPs; @@ -2450,7 +2517,7 @@ PP(pp_fttext) register SV *sv; GV *gv; - if (op->op_flags & OPf_REF) + if (PL_op->op_flags & OPf_REF) gv = cGVOP->op_gv; else if (isGV(TOPs)) gv = (GV*)POPs; @@ -2461,28 +2528,28 @@ PP(pp_fttext) if (gv) { EXTEND(SP, 1); - if (gv == defgv) { - if (statgv) - io = GvIO(statgv); + if (gv == PL_defgv) { + if (PL_statgv) + io = GvIO(PL_statgv); else { - sv = statname; + sv = PL_statname; goto really_filename; } } else { - statgv = gv; - laststatval = -1; - sv_setpv(statname, ""); - io = GvIO(statgv); + PL_statgv = gv; + PL_laststatval = -1; + sv_setpv(PL_statname, ""); + io = GvIO(PL_statgv); } if (io && IoIFP(io)) { if (! PerlIO_has_base(IoIFP(io))) DIE("-T and -B not implemented on filehandles"); - laststatval = PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &statcache); - if (laststatval < 0) + PL_laststatval = PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache); + if (PL_laststatval < 0) RETPUSHUNDEF; - if (S_ISDIR(statcache.st_mode)) /* handle NFS glitch */ - if (op->op_type == OP_FTTEXT) + if (S_ISDIR(PL_statcache.st_mode)) /* handle NFS glitch */ + if (PL_op->op_type == OP_FTTEXT) RETPUSHNO; else RETPUSHYES; @@ -2500,8 +2567,8 @@ PP(pp_fttext) len = 512; } else { - if (dowarn) - warn("Test on unopened file <%s>", + if (ckWARN(WARN_UNOPENED)) + warner(WARN_UNOPENED, "Test on unopened file <%s>", GvENAME(cGVOP->op_gv)); SETERRNO(EBADF,RMS$_IFI); RETPUSHUNDEF; @@ -2510,26 +2577,26 @@ PP(pp_fttext) else { sv = POPs; really_filename: - statgv = Nullgv; - laststatval = -1; - sv_setpv(statname, SvPV(sv, na)); + PL_statgv = Nullgv; + PL_laststatval = -1; + sv_setpv(PL_statname, SvPV(sv, PL_na)); #ifdef HAS_OPEN3 - i = PerlLIO_open3(SvPV(sv, na), O_RDONLY, 0); + i = PerlLIO_open3(SvPV(sv, PL_na), O_RDONLY, 0); #else - i = PerlLIO_open(SvPV(sv, na), 0); + i = PerlLIO_open(SvPV(sv, PL_na), 0); #endif if (i < 0) { - if (dowarn && strchr(SvPV(sv, na), '\n')) - warn(warn_nl, "open"); + if (ckWARN(WARN_NEWLINE) && strchr(SvPV(sv, PL_na), '\n')) + warner(WARN_NEWLINE, warn_nl, "open"); RETPUSHUNDEF; } - laststatval = PerlLIO_fstat(i, &statcache); - if (laststatval < 0) + PL_laststatval = PerlLIO_fstat(i, &PL_statcache); + if (PL_laststatval < 0) RETPUSHUNDEF; len = PerlLIO_read(i, tbuf, 512); (void)PerlLIO_close(i); if (len <= 0) { - if (S_ISDIR(statcache.st_mode) && op->op_type == OP_FTTEXT) + if (S_ISDIR(PL_statcache.st_mode) && PL_op->op_type == OP_FTTEXT) RETPUSHNO; /* special case NFS directories */ RETPUSHYES; /* null file is anything */ } @@ -2544,15 +2611,20 @@ PP(pp_fttext) odd += len; break; } +#ifdef EBCDIC + else if (!(isPRINT(*s) || isSPACE(*s))) + odd++; +#else else if (*s & 128) odd++; else if (*s < 32 && *s != '\n' && *s != '\r' && *s != '\b' && *s != '\t' && *s != '\f' && *s != 27) odd++; +#endif } - if ((odd * 3 > len) == (op->op_type == OP_FTTEXT)) /* allow 1/3 odd */ + if ((odd * 3 > len) == (PL_op->op_type == OP_FTTEXT)) /* allow 1/3 odd */ RETPUSHNO; else RETPUSHYES; @@ -2576,21 +2648,28 @@ PP(pp_chdir) else tmps = POPp; if (!tmps || !*tmps) { - svp = hv_fetch(GvHVn(envgv), "HOME", 4, FALSE); + svp = hv_fetch(GvHVn(PL_envgv), "HOME", 4, FALSE); if (svp) - tmps = SvPV(*svp, na); + tmps = SvPV(*svp, PL_na); } if (!tmps || !*tmps) { - svp = hv_fetch(GvHVn(envgv), "LOGDIR", 6, FALSE); + svp = hv_fetch(GvHVn(PL_envgv), "LOGDIR", 6, FALSE); if (svp) - tmps = SvPV(*svp, na); + tmps = SvPV(*svp, PL_na); + } +#ifdef VMS + if (!tmps || !*tmps) { + svp = hv_fetch(GvHVn(PL_envgv), "SYS$LOGIN", 9, FALSE); + if (svp) + tmps = SvPV(*svp, PL_na); } +#endif TAINT_PROPER("chdir"); PUSHi( PerlDir_chdir(tmps) >= 0 ); #ifdef VMS /* Clear the DEFAULT element of ENV so we'll get the new value * in the future. */ - hv_delete(GvHVn(envgv),"DEFAULT",7,G_DISCARD); + hv_delete(GvHVn(PL_envgv),"DEFAULT",7,G_DISCARD); #endif RETURN; } @@ -2600,7 +2679,7 @@ PP(pp_chown) djSP; dMARK; dTARGET; I32 value; #ifdef HAS_CHOWN - value = (I32)apply(op->op_type, MARK, SP); + value = (I32)apply(PL_op->op_type, MARK, SP); SP = MARK; PUSHi(value); RETURN; @@ -2627,7 +2706,7 @@ PP(pp_unlink) { djSP; dMARK; dTARGET; I32 value; - value = (I32)apply(op->op_type, MARK, SP); + value = (I32)apply(PL_op->op_type, MARK, SP); SP = MARK; PUSHi(value); RETURN; @@ -2637,7 +2716,7 @@ PP(pp_chmod) { djSP; dMARK; dTARGET; I32 value; - value = (I32)apply(op->op_type, MARK, SP); + value = (I32)apply(PL_op->op_type, MARK, SP); SP = MARK; PUSHi(value); RETURN; @@ -2647,7 +2726,7 @@ PP(pp_utime) { djSP; dMARK; dTARGET; I32 value; - value = (I32)apply(op->op_type, MARK, SP); + value = (I32)apply(PL_op->op_type, MARK, SP); SP = MARK; PUSHi(value); RETURN; @@ -2659,16 +2738,16 @@ PP(pp_rename) int anum; char *tmps2 = POPp; - char *tmps = SvPV(TOPs, na); + char *tmps = SvPV(TOPs, PL_na); TAINT_PROPER("rename"); #ifdef HAS_RENAME - anum = rename(tmps, tmps2); + anum = PerlLIO_rename(tmps, tmps2); #else - if (!(anum = Stat(tmps, &statbuf))) { + if (!(anum = PerlLIO_stat(tmps, &PL_statbuf))) { if (same_dirent(tmps2, tmps)) /* can always rename to same name */ anum = 1; else { - if (euid || Stat(tmps2, &statbuf) < 0 || !S_ISDIR(statbuf.st_mode)) + if (PL_euid || PerlLIO_stat(tmps2, &PL_statbuf) < 0 || !S_ISDIR(PL_statbuf.st_mode)) (void)UNLINK(tmps2); if (!(anum = link(tmps, tmps2))) anum = UNLINK(tmps); @@ -2684,7 +2763,7 @@ PP(pp_link) djSP; dTARGET; #ifdef HAS_LINK char *tmps2 = POPp; - char *tmps = SvPV(TOPs, na); + char *tmps = SvPV(TOPs, PL_na); TAINT_PROPER("link"); SETi( link(tmps, tmps2) >= 0 ); #else @@ -2698,7 +2777,7 @@ PP(pp_symlink) djSP; dTARGET; #ifdef HAS_SYMLINK char *tmps2 = POPp; - char *tmps = SvPV(TOPs, na); + char *tmps = SvPV(TOPs, PL_na); TAINT_PROPER("symlink"); SETi( symlink(tmps, tmps2) >= 0 ); RETURN; @@ -2756,7 +2835,7 @@ char *filename; if (myfp) { SV *tmpsv = sv_newmortal(); - /* Need to save/restore 'rs' ?? */ + /* Need to save/restore 'PL_rs' ?? */ s = sv_gets(tmpsv, myfp, 0); (void)PerlProc_pclose(myfp); if (s != Nullch) { @@ -2805,8 +2884,8 @@ char *filename; return 0; } else { /* some mkdirs return no failure indication */ - anum = (Stat(save_filename, &statbuf) >= 0); - if (op->op_type == OP_RMDIR) + anum = (PerlLIO_stat(save_filename, &PL_statbuf) >= 0); + if (PL_op->op_type == OP_RMDIR) anum = !anum; if (anum) SETERRNO(0,0); @@ -2827,7 +2906,7 @@ PP(pp_mkdir) #ifndef HAS_MKDIR int oldumask; #endif - char *tmps = SvPV(TOPs, na); + char *tmps = SvPV(TOPs, PL_na); TAINT_PROPER("mkdir"); #ifdef HAS_MKDIR @@ -3055,7 +3134,7 @@ PP(pp_fork) /*SUPPRESS 560*/ if (tmpgv = gv_fetchpv("$", TRUE, SVt_PV)) sv_setiv(GvSV(tmpgv), (IV)getpid()); - hv_clear(pidstatus); /* no kids, so don't wait for 'em */ + hv_clear(PL_pidstatus); /* no kids, so don't wait for 'em */ } PUSHi(childpid); RETURN; @@ -3109,8 +3188,8 @@ PP(pp_system) Sigsave_t ihand,qhand; /* place to save signals during system() */ if (SP - MARK == 1) { - if (tainting) { - char *junk = SvPV(TOPs, na); + if (PL_tainting) { + char *junk = SvPV(TOPs, PL_na); TAINT_ENV(); TAINT_PROPER("system"); } @@ -3139,25 +3218,25 @@ PP(pp_system) PUSHi(STATUS_CURRENT); RETURN; } - if (op->op_flags & OPf_STACKED) { + if (PL_op->op_flags & OPf_STACKED) { SV *really = *++MARK; value = (I32)do_aexec(really, MARK, SP); } else if (SP - MARK != 1) value = (I32)do_aexec(Nullsv, MARK, SP); else { - value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), na)); + value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), PL_na)); } PerlProc__exit(-1); #else /* ! FORK or VMS or OS/2 */ - if (op->op_flags & OPf_STACKED) { + if (PL_op->op_flags & OPf_STACKED) { SV *really = *++MARK; value = (I32)do_aspawn(really, (void **)MARK, (void **)SP); } else if (SP - MARK != 1) value = (I32)do_aspawn(Nullsv, (void **)MARK, (void **)SP); else { - value = (I32)do_spawn(SvPVx(sv_mortalcopy(*SP), na)); + value = (I32)do_spawn(SvPVx(sv_mortalcopy(*SP), PL_na)); } STATUS_NATIVE_SET(value); do_execfree(); @@ -3172,7 +3251,7 @@ PP(pp_exec) djSP; dMARK; dORIGMARK; dTARGET; I32 value; - if (op->op_flags & OPf_STACKED) { + if (PL_op->op_flags & OPf_STACKED) { SV *really = *++MARK; value = (I32)do_aexec(really, MARK, SP); } @@ -3183,15 +3262,15 @@ PP(pp_exec) value = (I32)do_aexec(Nullsv, MARK, SP); #endif else { - if (tainting) { - char *junk = SvPV(*SP, na); + if (PL_tainting) { + char *junk = SvPV(*SP, PL_na); TAINT_ENV(); TAINT_PROPER("exec"); } #ifdef VMS - value = (I32)vms_do_exec(SvPVx(sv_mortalcopy(*SP), na)); + value = (I32)vms_do_exec(SvPVx(sv_mortalcopy(*SP), PL_na)); #else - value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), na)); + value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), PL_na)); #endif } SP = ORIGMARK; @@ -3204,7 +3283,7 @@ PP(pp_kill) djSP; dMARK; dTARGET; I32 value; #ifdef HAS_KILL - value = (I32)apply(op->op_type, MARK, SP); + value = (I32)apply(PL_op->op_type, MARK, SP); SP = MARK; PUSHi(value); RETURN; @@ -3350,18 +3429,18 @@ PP(pp_tms) EXTEND(SP, 4); #ifndef VMS - (void)times(×buf); + (void)PerlProc_times(&PL_timesbuf); #else - (void)times((tbuffer_t *)×buf); /* time.h uses different name for */ - /* struct tms, though same data */ - /* is returned. */ + (void)PerlProc_times((tbuffer_t *)&PL_timesbuf); /* time.h uses different name for */ + /* struct tms, though same data */ + /* is returned. */ #endif - PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_utime)/HZ))); + PUSHs(sv_2mortal(newSVnv(((double)PL_timesbuf.tms_utime)/HZ))); if (GIMME == G_ARRAY) { - PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_stime)/HZ))); - PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_cutime)/HZ))); - PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_cstime)/HZ))); + PUSHs(sv_2mortal(newSVnv(((double)PL_timesbuf.tms_stime)/HZ))); + PUSHs(sv_2mortal(newSVnv(((double)PL_timesbuf.tms_cutime)/HZ))); + PUSHs(sv_2mortal(newSVnv(((double)PL_timesbuf.tms_cstime)/HZ))); } RETURN; #endif /* HAS_TIMES */ @@ -3390,7 +3469,7 @@ PP(pp_gmtime) when = (Time_t)SvIVx(POPs); #endif - if (op->op_type == OP_LOCALTIME) + if (PL_op->op_type == OP_LOCALTIME) tmbuf = localtime(&when); else tmbuf = gmtime(&when); @@ -3452,10 +3531,10 @@ PP(pp_sleep) (void)time(&lasttime); if (MAXARG < 1) - Pause(); + PerlProc_pause(); else { duration = POPi; - sleep((unsigned int)duration); + PerlProc_sleep((unsigned int)duration); } (void)time(&when); XPUSHi(when - lasttime); @@ -3483,7 +3562,7 @@ PP(pp_shmwrite) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) djSP; dMARK; dTARGET; - I32 value = (I32)(do_shmio(op->op_type, MARK, SP) >= 0); + I32 value = (I32)(do_shmio(PL_op->op_type, MARK, SP) >= 0); SP = MARK; PUSHi(value); RETURN; @@ -3536,7 +3615,7 @@ PP(pp_semget) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) djSP; dMARK; dTARGET; - int anum = do_ipcget(op->op_type, MARK, SP); + int anum = do_ipcget(PL_op->op_type, MARK, SP); SP = MARK; if (anum == -1) RETPUSHUNDEF; @@ -3551,7 +3630,7 @@ PP(pp_semctl) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) djSP; dMARK; dTARGET; - int anum = do_ipcctl(op->op_type, MARK, SP); + int anum = do_ipcctl(PL_op->op_type, MARK, SP); SP = MARK; if (anum == -1) RETSETUNDEF; @@ -3604,36 +3683,41 @@ PP(pp_ghostent) { djSP; #if defined(HAS_GETHOSTBYNAME) || defined(HAS_GETHOSTBYADDR) || defined(HAS_GETHOSTENT) - I32 which = op->op_type; + I32 which = PL_op->op_type; register char **elem; register SV *sv; -#if defined(HAS_GETHOSTENT) && !defined(DONT_DECLARE_STD) +#ifndef HAS_GETHOST_PROTOS /* XXX Do we need individual probes? */ struct hostent *PerlSock_gethostbyaddr(Netdb_host_t, Netdb_hlen_t, int); struct hostent *PerlSock_gethostbyname(Netdb_name_t); -#ifndef PerlSock_gethostent struct hostent *PerlSock_gethostent(void); #endif -#endif struct hostent *hent; unsigned long len; EXTEND(SP, 10); - if (which == OP_GHBYNAME) { + if (which == OP_GHBYNAME) +#ifdef HAS_GETHOSTBYNAME hent = PerlSock_gethostbyname(POPp); - } +#else + DIE(no_sock_func, "gethostbyname"); +#endif else if (which == OP_GHBYADDR) { +#ifdef HAS_GETHOSTBYADDR int addrtype = POPi; SV *addrsv = POPs; STRLEN addrlen; Netdb_host_t addr = (Netdb_host_t) SvPV(addrsv, addrlen); hent = PerlSock_gethostbyaddr(addr, (Netdb_hlen_t) addrlen, addrtype); +#else + DIE(no_sock_func, "gethostbyaddr"); +#endif } else #ifdef HAS_GETHOSTENT hent = PerlSock_gethostent(); #else - DIE("gethostent not implemented"); + DIE(no_sock_func, "gethostent"); #endif #ifdef HOST_NOT_FOUND @@ -3655,26 +3739,26 @@ PP(pp_ghostent) } if (hent) { - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setpv(sv, (char*)hent->h_name); - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); for (elem = hent->h_aliases; elem && *elem; elem++) { sv_catpv(sv, *elem); if (elem[1]) sv_catpvn(sv, " ", 1); } - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setiv(sv, (IV)hent->h_addrtype); - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); len = hent->h_length; sv_setiv(sv, (IV)len); #ifdef h_addr for (elem = hent->h_addr_list; elem && *elem; elem++) { - XPUSHs(sv = sv_mortalcopy(&sv_no)); + XPUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setpvn(sv, *elem, len); } #else - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); if (hent->h_addr) sv_setpvn(sv, hent->h_addr, len); #endif /* h_addr */ @@ -3707,25 +3791,37 @@ PP(pp_gnetent) { djSP; #if defined(HAS_GETNETBYNAME) || defined(HAS_GETNETBYADDR) || defined(HAS_GETNETENT) - I32 which = op->op_type; + I32 which = PL_op->op_type; register char **elem; register SV *sv; -#ifdef NETDB_H_OMITS_GETNET - struct netent *getnetbyaddr(Netdb_net_t, int); - struct netent *getnetbyname(Netdb_name_t); - struct netent *getnetent(void); +#ifndef HAS_GETNET_PROTOS /* XXX Do we need individual probes? */ + struct netent *PerlSock_getnetbyaddr(Netdb_net_t, int); + struct netent *PerlSock_getnetbyname(Netdb_name_t); + struct netent *PerlSock_getnetent(void); #endif struct netent *nent; if (which == OP_GNBYNAME) - nent = getnetbyname(POPp); +#ifdef HAS_GETNETBYNAME + nent = PerlSock_getnetbyname(POPp); +#else + DIE(no_sock_func, "getnetbyname"); +#endif else if (which == OP_GNBYADDR) { +#ifdef HAS_GETNETBYADDR int addrtype = POPi; Netdb_net_t addr = (Netdb_net_t) U_L(POPn); - nent = getnetbyaddr(addr, addrtype); + nent = PerlSock_getnetbyaddr(addr, addrtype); +#else + DIE(no_sock_func, "getnetbyaddr"); +#endif } else - nent = getnetent(); +#ifdef HAS_GETNETENT + nent = PerlSock_getnetent(); +#else + DIE(no_sock_func, "getnetent"); +#endif EXTEND(SP, 4); if (GIMME != G_ARRAY) { @@ -3740,17 +3836,17 @@ PP(pp_gnetent) } if (nent) { - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setpv(sv, nent->n_name); - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); for (elem = nent->n_aliases; elem && *elem; elem++) { sv_catpv(sv, *elem); if (elem[1]) sv_catpvn(sv, " ", 1); } - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setiv(sv, (IV)nent->n_addrtype); - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setiv(sv, (IV)nent->n_net); } @@ -3782,16 +3878,14 @@ PP(pp_gprotoent) { djSP; #if defined(HAS_GETPROTOBYNAME) || defined(HAS_GETPROTOBYNUMBER) || defined(HAS_GETPROTOENT) - I32 which = op->op_type; + I32 which = PL_op->op_type; register char **elem; register SV *sv; -#ifndef DONT_DECLARE_STD +#ifndef HAS_GETPROTO_PROTOS /* XXX Do we need individual probes? */ struct protoent *PerlSock_getprotobyname(Netdb_name_t); struct protoent *PerlSock_getprotobynumber(int); -#ifndef PerlSock_getprotoent struct protoent *PerlSock_getprotoent(void); #endif -#endif struct protoent *pent; if (which == OP_GPBYNAME) @@ -3826,15 +3920,15 @@ PP(pp_gprotoent) } if (pent) { - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setpv(sv, pent->p_name); - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); for (elem = pent->p_aliases; elem && *elem; elem++) { sv_catpv(sv, *elem); if (elem[1]) sv_catpvn(sv, " ", 1); } - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setiv(sv, (IV)pent->p_proto); } @@ -3866,19 +3960,18 @@ PP(pp_gservent) { djSP; #if defined(HAS_GETSERVBYNAME) || defined(HAS_GETSERVBYPORT) || defined(HAS_GETSERVENT) - I32 which = op->op_type; + I32 which = PL_op->op_type; register char **elem; register SV *sv; -#ifndef DONT_DECLARE_STD +#ifndef HAS_GETSERV_PROTOS /* XXX Do we need individual probes? */ struct servent *PerlSock_getservbyname(Netdb_name_t, Netdb_name_t); struct servent *PerlSock_getservbyport(int, Netdb_name_t); -#ifndef PerlSock_getservent struct servent *PerlSock_getservent(void); #endif -#endif struct servent *sent; if (which == OP_GSBYNAME) { +#ifdef HAS_GETSERVBYNAME char *proto = POPp; char *name = POPp; @@ -3886,8 +3979,12 @@ PP(pp_gservent) proto = Nullch; sent = PerlSock_getservbyname(name, proto); +#else + DIE(no_sock_func, "getservbyname"); +#endif } else if (which == OP_GSBYPORT) { +#ifdef HAS_GETSERVBYPORT char *proto = POPp; unsigned short port = POPu; @@ -3895,6 +3992,9 @@ PP(pp_gservent) port = PerlSock_htons(port); #endif sent = PerlSock_getservbyport(port, proto); +#else + DIE(no_sock_func, "getservbyport"); +#endif } else #ifdef HAS_GETSERVENT @@ -3921,21 +4021,21 @@ PP(pp_gservent) } if (sent) { - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setpv(sv, sent->s_name); - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); for (elem = sent->s_aliases; elem && *elem; elem++) { sv_catpv(sv, *elem); if (elem[1]) sv_catpvn(sv, " ", 1); } - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); #ifdef HAS_NTOHS - sv_setiv(sv, (IV)ntohs(sent->s_port)); + sv_setiv(sv, (IV)PerlSock_ntohs(sent->s_port)); #else sv_setiv(sv, (IV)(sent->s_port)); #endif - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setpv(sv, sent->s_proto); } @@ -3949,7 +4049,7 @@ PP(pp_shostent) { djSP; #ifdef HAS_SETHOSTENT - sethostent(TOPi); + PerlSock_sethostent(TOPi); RETSETYES; #else DIE(no_sock_func, "sethostent"); @@ -3960,7 +4060,7 @@ PP(pp_snetent) { djSP; #ifdef HAS_SETNETENT - setnetent(TOPi); + PerlSock_setnetent(TOPi); RETSETYES; #else DIE(no_sock_func, "setnetent"); @@ -3971,7 +4071,7 @@ PP(pp_sprotoent) { djSP; #ifdef HAS_SETPROTOENT - setprotoent(TOPi); + PerlSock_setprotoent(TOPi); RETSETYES; #else DIE(no_sock_func, "setprotoent"); @@ -3982,7 +4082,7 @@ PP(pp_sservent) { djSP; #ifdef HAS_SETSERVENT - setservent(TOPi); + PerlSock_setservent(TOPi); RETSETYES; #else DIE(no_sock_func, "setservent"); @@ -3993,8 +4093,8 @@ PP(pp_ehostent) { djSP; #ifdef HAS_ENDHOSTENT - endhostent(); - EXTEND(sp,1); + PerlSock_endhostent(); + EXTEND(SP,1); RETPUSHYES; #else DIE(no_sock_func, "endhostent"); @@ -4005,8 +4105,8 @@ PP(pp_enetent) { djSP; #ifdef HAS_ENDNETENT - endnetent(); - EXTEND(sp,1); + PerlSock_endnetent(); + EXTEND(SP,1); RETPUSHYES; #else DIE(no_sock_func, "endnetent"); @@ -4017,8 +4117,8 @@ PP(pp_eprotoent) { djSP; #ifdef HAS_ENDPROTOENT - endprotoent(); - EXTEND(sp,1); + PerlSock_endprotoent(); + EXTEND(SP,1); RETPUSHYES; #else DIE(no_sock_func, "endprotoent"); @@ -4029,8 +4129,8 @@ PP(pp_eservent) { djSP; #ifdef HAS_ENDSERVENT - endservent(); - EXTEND(sp,1); + PerlSock_endservent(); + EXTEND(SP,1); RETPUSHYES; #else DIE(no_sock_func, "endservent"); @@ -4058,8 +4158,8 @@ PP(pp_gpwuid) PP(pp_gpwent) { djSP; -#ifdef HAS_PASSWD - I32 which = op->op_type; +#if defined(HAS_PASSWD) && defined(HAS_GETPWENT) + I32 which = PL_op->op_type; register SV *sv; struct passwd *pwent; @@ -4083,45 +4183,61 @@ PP(pp_gpwent) } if (pwent) { - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setpv(sv, pwent->pw_name); - PUSHs(sv = sv_mortalcopy(&sv_no)); + + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); +#ifdef PWPASSWD sv_setpv(sv, pwent->pw_passwd); - PUSHs(sv = sv_mortalcopy(&sv_no)); +#endif + + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setiv(sv, (IV)pwent->pw_uid); - PUSHs(sv = sv_mortalcopy(&sv_no)); + + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setiv(sv, (IV)pwent->pw_gid); - PUSHs(sv = sv_mortalcopy(&sv_no)); + + /* pw_change, pw_quota, and pw_age are mutually exclusive. */ + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); #ifdef PWCHANGE sv_setiv(sv, (IV)pwent->pw_change); #else -#ifdef PWQUOTA +# ifdef PWQUOTA sv_setiv(sv, (IV)pwent->pw_quota); -#else -#ifdef PWAGE +# else +# ifdef PWAGE sv_setpv(sv, pwent->pw_age); +# endif +# endif #endif -#endif -#endif - PUSHs(sv = sv_mortalcopy(&sv_no)); + + /* pw_class and pw_comment are mutually exclusive. */ + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); #ifdef PWCLASS sv_setpv(sv, pwent->pw_class); #else -#ifdef PWCOMMENT +# ifdef PWCOMMENT sv_setpv(sv, pwent->pw_comment); +# endif #endif -#endif - PUSHs(sv = sv_mortalcopy(&sv_no)); + + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); +#ifdef PWGECOS sv_setpv(sv, pwent->pw_gecos); +#endif #ifndef INCOMPLETE_TAINTS + /* pw_gecos is tainted because user himself can diddle with it. */ SvTAINTED_on(sv); #endif - PUSHs(sv = sv_mortalcopy(&sv_no)); + + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setpv(sv, pwent->pw_dir); - PUSHs(sv = sv_mortalcopy(&sv_no)); + + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setpv(sv, pwent->pw_shell); + #ifdef PWEXPIRE - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setiv(sv, (IV)pwent->pw_expire); #endif } @@ -4134,7 +4250,7 @@ PP(pp_gpwent) PP(pp_spwent) { djSP; -#if defined(HAS_PASSWD) && !defined(CYGWIN32) +#if defined(HAS_PASSWD) && defined(HAS_SETPWENT) && !defined(CYGWIN32) setpwent(); RETPUSHYES; #else @@ -4145,7 +4261,7 @@ PP(pp_spwent) PP(pp_epwent) { djSP; -#ifdef HAS_PASSWD +#if defined(HAS_PASSWD) && defined(HAS_ENDPWENT) endpwent(); RETPUSHYES; #else @@ -4174,8 +4290,8 @@ PP(pp_ggrgid) PP(pp_ggrent) { djSP; -#ifdef HAS_GROUP - I32 which = op->op_type; +#if defined(HAS_GROUP) && defined(HAS_GETGRENT) + I32 which = PL_op->op_type; register char **elem; register SV *sv; struct group *grent; @@ -4200,13 +4316,18 @@ PP(pp_ggrent) } if (grent) { - PUSHs(sv = sv_mortalcopy(&sv_no)); + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setpv(sv, grent->gr_name); - PUSHs(sv = sv_mortalcopy(&sv_no)); + + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); +#ifdef GRPASSWD sv_setpv(sv, grent->gr_passwd); - PUSHs(sv = sv_mortalcopy(&sv_no)); +#endif + + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); sv_setiv(sv, (IV)grent->gr_gid); - PUSHs(sv = sv_mortalcopy(&sv_no)); + + PUSHs(sv = sv_mortalcopy(&PL_sv_no)); for (elem = grent->gr_mem; elem && *elem; elem++) { sv_catpv(sv, *elem); if (elem[1]) @@ -4223,7 +4344,7 @@ PP(pp_ggrent) PP(pp_sgrent) { djSP; -#ifdef HAS_GROUP +#if defined(HAS_GROUP) && defined(HAS_SETGRENT) setgrent(); RETPUSHYES; #else @@ -4234,7 +4355,7 @@ PP(pp_sgrent) PP(pp_egrent) { djSP; -#ifdef HAS_GROUP +#if defined(HAS_GROUP) && defined(HAS_ENDGRENT) endgrent(); RETPUSHYES; #else @@ -4248,7 +4369,7 @@ PP(pp_getlogin) #ifdef HAS_GETLOGIN char *tmps; EXTEND(SP, 1); - if (!(tmps = getlogin())) + if (!(tmps = PerlProc_getlogin())) RETPUSHUNDEF; PUSHp(tmps, strlen(tmps)); RETURN; @@ -4261,7 +4382,7 @@ PP(pp_getlogin) PP(pp_syscall) { -#ifdef HAS_SYSCALL +#ifdef HAS_SYSCALL djSP; dMARK; dORIGMARK; dTARGET; register I32 items = SP - MARK; unsigned long a[20]; @@ -4269,7 +4390,7 @@ PP(pp_syscall) I32 retval = -1; MAGIC *mg; - if (tainting) { + if (PL_tainting) { while (++MARK <= SP) { if (SvTAINTED(*MARK)) { TAINT; @@ -4287,10 +4408,10 @@ PP(pp_syscall) while (++MARK <= SP) { if (SvNIOK(*MARK) || !i) a[i++] = SvIV(*MARK); - else if (*MARK == &sv_undef) + else if (*MARK == &PL_sv_undef) a[i++] = 0; else - a[i++] = (unsigned long)SvPV_force(*MARK, na); + a[i++] = (unsigned long)SvPV_force(*MARK, PL_na); if (i > 15) break; } @@ -4475,4 +4596,3 @@ int operation; } #endif /* LOCKF_EMULATE_FLOCK */ -