X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pp_sys.c;h=ce32fc5767b9e03c51bb35702ed167f04b9f6950;hb=8803afc236dca2c2990fc3236c7c43e710a099fb;hp=6f8b4493b79eab17597d48b39507e2e5213d7947;hpb=f289f7d2518e7a8a82114282e774adf50fa6ce85;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pp_sys.c b/pp_sys.c index 6f8b449..ce32fc5 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -22,6 +22,12 @@ # include #endif +#ifdef HAS_SYSCALL +#ifdef __cplusplus +extern "C" int syscall(unsigned long,...); +#endif +#endif + #ifdef I_SYS_WAIT # include #endif @@ -30,16 +36,11 @@ # include #endif -/* Put this after #includes because fork and vfork prototypes may - conflict. -*/ -#ifndef HAS_VFORK -# define vfork fork -#endif - #if defined(HAS_SOCKET) && !defined(VMS) /* VMS handles sockets via vmsish.h */ # include -# include +# ifdef I_NETDB +# include +# endif # ifndef ENOTSOCK # ifdef I_NET_ERRNO # include @@ -53,7 +54,11 @@ #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 @@ -78,7 +83,7 @@ extern int h_errno; #endif #ifdef I_UTIME -# ifdef WIN32 +# if defined(_MSC_VER) || defined(__MINGW32__) # include # else # include @@ -91,6 +96,20 @@ extern int h_errno; #include #endif +/* Put this after #includes because fork and vfork prototypes may conflict. */ +#ifndef HAS_VFORK +# define vfork fork +#endif + +/* Put this after #includes because defines _XOPEN_*. */ +#ifndef Sock_size_t +# if _XOPEN_VERSION >= 5 || defined(_XOPEN_SOURCE_EXTENDED) || defined(__GLIBC__) +# define Sock_size_t Size_t +# else +# define Sock_size_t int +# endif +#endif + #if !defined(HAS_MKDIR) || !defined(HAS_RMDIR) static int dooneliner _((char *cmd, char *filename)); #endif @@ -99,7 +118,7 @@ static int dooneliner _((char *cmd, char *filename)); # ifdef my_chsize /* Probably #defined to Perl_my_chsize in embed.h */ # undef my_chsize # endif -# define my_chsize chsize +# define my_chsize PerlLIO_chsize #endif #ifdef HAS_FLOCK @@ -147,18 +166,36 @@ static int dooneliner _((char *cmd, char *filename)); #endif /* no flock() */ +#ifndef MAXPATHLEN +# ifdef PATH_MAX +# define MAXPATHLEN PATH_MAX +# else +# define MAXPATHLEN 1024 +# endif +#endif + +#define ZBTLEN 10 +static char zero_but_true[ZBTLEN + 1] = "0 but true"; /* Pushy I/O. */ PP(pp_backtick) { - dSP; dTARGET; + djSP; dTARGET; PerlIO *fp; char *tmps = POPp; + I32 gimme = GIMME_V; + TAINT_PROPER("``"); - fp = my_popen(tmps, "r"); + fp = PerlProc_popen(tmps, "r"); if (fp) { - if (GIMME == G_SCALAR) { + if (gimme == G_VOID) { + char tmpbuf[256]; + while (PerlIO_read(fp, tmpbuf, sizeof tmpbuf) > 0) + /*SUPPRESS 530*/ + ; + } + else if (gimme == G_SCALAR) { sv_setpv(TARG, ""); /* note that this preserves previous buffer */ while (sv_gets(TARG, fp, SvCUR(TARG)) != Nullch) /*SUPPRESS 530*/ @@ -183,12 +220,12 @@ PP(pp_backtick) SvTAINTED_on(sv); } } - STATUS_NATIVE_SET(my_pclose(fp)); + STATUS_NATIVE_SET(PerlProc_pclose(fp)); TAINT; /* "I believe that this is not gratuitous!" */ } else { STATUS_NATIVE_SET(-1); - if (GIMME == G_SCALAR) + if (gimme == G_SCALAR) RETPUSHUNDEF; } @@ -200,6 +237,17 @@ PP(pp_glob) OP *result; ENTER; +#ifndef VMS + if (tainting) { + /* + * The external globbing program may use things we can't control, + * so for security reasons we must assume the worst. + */ + TAINT; + taint_proper(no_security, "glob"); + } +#endif /* !VMS */ + SAVESPTR(last_in_gv); /* We don't want this to be permanent. */ last_in_gv = (GV*)*stack_sp--; @@ -230,7 +278,7 @@ PP(pp_rcatline) PP(pp_warn) { - dSP; dMARK; + djSP; dMARK; char *tmps; if (SP - MARK != 1) { dTARGET; @@ -242,11 +290,10 @@ PP(pp_warn) tmps = SvPV(TOPs, na); } if (!tmps || !*tmps) { - SV *error = GvSV(errgv); - (void)SvUPGRADE(error, SVt_PV); - if (SvPOK(error) && SvCUR(error)) - sv_catpv(error, "\t...caught"); - tmps = SvPV(error, na); + (void)SvUPGRADE(ERRSV, SVt_PV); + if (SvPOK(ERRSV) && SvCUR(ERRSV)) + sv_catpv(ERRSV, "\t...caught"); + tmps = SvPV(ERRSV, na); } if (!tmps || !*tmps) tmps = "Warning: something's wrong"; @@ -256,7 +303,7 @@ PP(pp_warn) PP(pp_die) { - dSP; dMARK; + djSP; dMARK; char *tmps; if (SP - MARK != 1) { dTARGET; @@ -268,11 +315,10 @@ PP(pp_die) tmps = SvPV(TOPs, na); } if (!tmps || !*tmps) { - SV *error = GvSV(errgv); - (void)SvUPGRADE(error, SVt_PV); - if (SvPOK(error) && SvCUR(error)) - sv_catpv(error, "\t...propagated"); - tmps = SvPV(error, na); + (void)SvUPGRADE(ERRSV, SVt_PV); + if (SvPOK(ERRSV) && SvCUR(ERRSV)) + sv_catpv(ERRSV, "\t...propagated"); + tmps = SvPV(ERRSV, na); } if (!tmps || !*tmps) tmps = "Died"; @@ -283,7 +329,7 @@ PP(pp_die) PP(pp_open) { - dSP; dTARGET; + djSP; dTARGET; GV *gv; SV *sv; char *tmps; @@ -312,21 +358,33 @@ PP(pp_open) PP(pp_close) { - dSP; + djSP; GV *gv; + MAGIC *mg; if (MAXARG == 0) gv = defoutgv; else gv = (GV*)POPs; + + if (SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) { + PUSHMARK(SP); + XPUSHs(mg->mg_obj); + PUTBACK; + ENTER; + perl_call_method("CLOSE", G_SCALAR); + LEAVE; + SPAGAIN; + RETURN; + } EXTEND(SP, 1); - PUSHs( do_close(gv, TRUE) ? &sv_yes : &sv_no ); + PUSHs(boolSV(do_close(gv, TRUE))); RETURN; } PP(pp_pipe_op) { - dSP; + djSP; #ifdef HAS_PIPE GV *rgv; GV *wgv; @@ -350,7 +408,7 @@ PP(pp_pipe_op) if (IoIFP(wstio)) do_close(wgv, FALSE); - if (pipe(fd) < 0) + if (PerlProc_pipe(fd) < 0) goto badexit; IoIFP(rstio) = PerlIO_fdopen(fd[0], "r"); @@ -361,9 +419,9 @@ PP(pp_pipe_op) if (!IoIFP(rstio) || !IoOFP(wstio)) { if (IoIFP(rstio)) PerlIO_close(IoIFP(rstio)); - else close(fd[0]); + else PerlLIO_close(fd[0]); if (IoOFP(wstio)) PerlIO_close(IoOFP(wstio)); - else close(fd[1]); + else PerlLIO_close(fd[1]); goto badexit; } @@ -378,7 +436,7 @@ badexit: PP(pp_fileno) { - dSP; dTARGET; + djSP; dTARGET; GV *gv; IO *io; PerlIO *fp; @@ -393,16 +451,16 @@ PP(pp_fileno) PP(pp_umask) { - dSP; dTARGET; + djSP; dTARGET; int anum; #ifdef HAS_UMASK if (MAXARG < 1) { - anum = umask(0); - (void)umask(anum); + anum = PerlLIO_umask(0); + (void)PerlLIO_umask(anum); } else - anum = umask(POPi); + anum = PerlLIO_umask(POPi); TAINT_PROPER("umask"); XPUSHi(anum); #else @@ -413,7 +471,7 @@ PP(pp_umask) PP(pp_binmode) { - dSP; + djSP; GV *gv; IO *io; PerlIO *fp; @@ -434,8 +492,19 @@ PP(pp_binmode) else RETPUSHUNDEF; #else - if (setmode(PerlIO_fileno(fp), OP_BINARY) != -1) + 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 @@ -452,64 +521,73 @@ PP(pp_binmode) } + PP(pp_tie) { - dSP; + djSP; + dMARK; SV *varsv; HV* stash; GV *gv; - BINOP myop; SV *sv; - SV **mark = stack_base + ++*markstack_ptr; /* reuse in entersub */ - I32 markoff = mark - stack_base - 1; + I32 markoff = MARK - stack_base; char *methname; - bool oldcatch = CATCH_GET; - - varsv = mark[0]; - if (SvTYPE(varsv) == SVt_PVHV) - methname = "TIEHASH"; - else if (SvTYPE(varsv) == SVt_PVAV) - methname = "TIEARRAY"; - else if (SvTYPE(varsv) == SVt_PVGV) - methname = "TIEHANDLE"; - else - methname = "TIESCALAR"; - - stash = gv_stashsv(mark[1], FALSE); - if (!stash || !(gv = gv_fetchmethod(stash, methname))) - DIE("Can't locate object method \"%s\" via package \"%s\"", - methname, SvPV(mark[1],na)); + int how = 'P'; + U32 items; - Zero(&myop, 1, BINOP); - myop.op_last = (OP *) &myop; - myop.op_next = Nullop; - myop.op_flags = OPf_KNOW|OPf_STACKED; - CATCH_SET(TRUE); - - ENTER; - SAVESPTR(op); - op = (OP *) &myop; - if (perldb && curstash != debstash) - op->op_private |= OPpENTERSUB_DB; - - XPUSHs((SV*)GvCV(gv)); - PUTBACK; - - if (op = pp_entersub()) - runops(); + varsv = *++MARK; + switch(SvTYPE(varsv)) { + case SVt_PVHV: + methname = "TIEHASH"; + break; + case SVt_PVAV: + methname = "TIEARRAY"; + break; + case SVt_PVGV: + methname = "TIEHANDLE"; + how = 'q'; + break; + default: + methname = "TIESCALAR"; + how = 'q'; + break; + } + items = SP - MARK++; + if (sv_isobject(*MARK)) { + ENTER; + PUSHSTACK(SI_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, FALSE); + if (!stash || !(gv = gv_fetchmethod(stash, methname))) { + DIE("Can't locate object method \"%s\" via package \"%s\"", + methname, SvPV(*MARK,na)); + } + ENTER; + PUSHSTACK(SI_MAGIC); + PUSHMARK(SP); + EXTEND(SP,items); + while (items--) + PUSHs(*MARK++); + PUTBACK; + perl_call_sv((SV*)GvCV(gv), G_SCALAR); + } SPAGAIN; - CATCH_SET(oldcatch); sv = TOPs; + POPSTACK(); if (sv_isobject(sv)) { - if (SvTYPE(varsv) == SVt_PVHV || SvTYPE(varsv) == SVt_PVAV) { - sv_unmagic(varsv, 'P'); - sv_magic(varsv, sv, 'P', Nullch, 0); - } - else { - sv_unmagic(varsv, 'q'); - sv_magic(varsv, sv, 'q', Nullch, 0); - } + sv_unmagic(varsv, how); + sv_magic(varsv, sv, how, Nullch, 0); } LEAVE; SP = stack_base + markoff; @@ -519,10 +597,9 @@ PP(pp_tie) PP(pp_untie) { - dSP; + djSP; SV * sv ; - - sv = POPs; + sv = POPs; if (dowarn) { MAGIC * mg ; @@ -547,7 +624,7 @@ PP(pp_untie) PP(pp_tied) { - dSP; + djSP; SV * sv ; MAGIC * mg ; @@ -563,20 +640,17 @@ PP(pp_tied) RETURN ; } } - RETPUSHUNDEF; } PP(pp_dbmopen) { - dSP; + djSP; HV *hv; dPOPPOPssrl; HV* stash; GV *gv; - BINOP myop; SV *sv; - bool oldcatch = CATCH_GET; hv = (HV*)POPs; @@ -591,21 +665,10 @@ PP(pp_dbmopen) DIE("No dbm on this machine"); } - Zero(&myop, 1, BINOP); - myop.op_last = (OP *) &myop; - myop.op_next = Nullop; - myop.op_flags = OPf_KNOW|OPf_STACKED; - CATCH_SET(TRUE); - ENTER; - SAVESPTR(op); - op = (OP *) &myop; - if (perldb && curstash != debstash) - op->op_private |= OPpENTERSUB_DB; - PUTBACK; - pp_pushmark(); + PUSHMARK(SP); - EXTEND(sp, 5); + EXTEND(SP, 5); PUSHs(sv); PUSHs(left); if (SvIV(right)) @@ -613,34 +676,26 @@ PP(pp_dbmopen) else PUSHs(sv_2mortal(newSViv(O_RDWR))); PUSHs(right); - PUSHs((SV*)GvCV(gv)); PUTBACK; - - if (op = pp_entersub()) - runops(); + perl_call_sv((SV*)GvCV(gv), G_SCALAR); SPAGAIN; if (!sv_isobject(TOPs)) { - sp--; - op = (OP *) &myop; - PUTBACK; - pp_pushmark(); - + SP--; + PUSHMARK(SP); PUSHs(sv); PUSHs(left); PUSHs(sv_2mortal(newSViv(O_RDONLY))); PUSHs(right); - PUSHs((SV*)GvCV(gv)); PUTBACK; - - if (op = pp_entersub()) - runops(); + perl_call_sv((SV*)GvCV(gv), G_SCALAR); SPAGAIN; } - CATCH_SET(oldcatch); - if (sv_isobject(TOPs)) + if (sv_isobject(TOPs)) { + sv_unmagic((SV *) hv, 'P'); sv_magic((SV*)hv, TOPs, 'P', Nullch, 0); + } LEAVE; RETURN; } @@ -652,7 +707,7 @@ PP(pp_dbmclose) PP(pp_sselect) { - dSP; dTARGET; + djSP; dTARGET; #ifdef HAS_SELECT register I32 i; register I32 j; @@ -750,7 +805,7 @@ PP(pp_sselect) #endif } - nfound = select( + nfound = PerlSock_select( maxlen * 8, (Select_fd_set_t) fd_sets[1], (Select_fd_set_t) fd_sets[2], @@ -785,9 +840,9 @@ PP(pp_sselect) } void -setdefout(gv) -GV *gv; +setdefout(GV *gv) { + dTHR; if (gv) (void)SvREFCNT_inc(gv); if (defoutgv) @@ -797,11 +852,11 @@ GV *gv; PP(pp_select) { - dSP; dTARGET; + djSP; dTARGET; GV *newdefout, *egv; HV *hv; - newdefout = (op->op_private > 0) ? ((GV *) POPs) : NULL; + newdefout = (op->op_private > 0) ? ((GV *) POPs) : (GV *) NULL; egv = GvEGV(defoutgv); if (!egv) @@ -831,7 +886,7 @@ PP(pp_select) PP(pp_getc) { - dSP; dTARGET; + djSP; dTARGET; GV *gv; MAGIC *mg; @@ -842,16 +897,17 @@ PP(pp_getc) if (!gv) gv = argvgv; - if (SvMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) { + if (SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) { + I32 gimme = GIMME_V; PUSHMARK(SP); XPUSHs(mg->mg_obj); PUTBACK; ENTER; - perl_call_method("GETC", GIMME); + perl_call_method("GETC", gimme); LEAVE; SPAGAIN; - if (GIMME == G_SCALAR) - SvSetSV_nosteal(TARG, TOPs); + if (gimme == G_SCALAR) + SvSetMagicSV_nosteal(TARG, TOPs); RETURN; } if (!gv || do_eof(gv)) /* make sure we have fp with something */ @@ -869,13 +925,11 @@ PP(pp_read) } static OP * -doform(cv,gv,retop) -CV *cv; -GV *gv; -OP *retop; +doform(CV *cv, GV *gv, OP *retop) { - register CONTEXT *cx; - I32 gimme = GIMME; + dTHR; + register PERL_CONTEXT *cx; + I32 gimme = GIMME_V; AV* padlist = CvPADLIST(cv); SV** svp = AvARRAY(padlist); @@ -894,7 +948,7 @@ OP *retop; PP(pp_enterwrite) { - dSP; + djSP; register GV *gv; register IO *io; GV *fgv; @@ -935,14 +989,14 @@ PP(pp_enterwrite) PP(pp_leavewrite) { - dSP; + djSP; GV *gv = cxstack[cxstack_ix].blk_sub.gv; register IO *io = GvIOp(gv); PerlIO *ofp = IoOFP(io); PerlIO *fp; SV **newsp; I32 gimme; - register CONTEXT *cx; + register PERL_CONTEXT *cx; DEBUG_f(PerlIO_printf(Perl_debug_log, "left=%ld, todo=%ld\n", (long)IoLINES_LEFT(io), (long)FmLINES(formtarget))); @@ -953,16 +1007,16 @@ PP(pp_leavewrite) CV *cv; if (!IoTOP_GV(io)) { GV *topgv; - char tmpbuf[256]; + SV *topname; if (!IoTOP_NAME(io)) { if (!IoFMT_NAME(io)) IoFMT_NAME(io) = savepv(GvNAME(gv)); - sprintf(tmpbuf, "%s_TOP", IoFMT_NAME(io)); - topgv = gv_fetchpv(tmpbuf,FALSE, SVt_PVFM); + topname = sv_2mortal(newSVpvf("%s_TOP", IoFMT_NAME(io))); + topgv = gv_fetchpv(SvPVX(topname), FALSE, SVt_PVFM); if ((topgv && GvFORM(topgv)) || !gv_fetchpv("top",FALSE,SVt_PVFM)) - IoTOP_NAME(io) = savepv(tmpbuf); + IoTOP_NAME(io) = savepv(SvPVX(topname)); else IoTOP_NAME(io) = savepv("top"); } @@ -1049,16 +1103,39 @@ PP(pp_leavewrite) PP(pp_prtf) { - dSP; dMARK; dORIGMARK; + djSP; dMARK; dORIGMARK; GV *gv; IO *io; PerlIO *fp; - SV *sv = NEWSV(0,0); + SV *sv; + MAGIC *mg; if (op->op_flags & OPf_STACKED) gv = (GV*)*++MARK; else gv = defoutgv; + + if (SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) { + if (MARK == ORIGMARK) { + MEXTEND(SP, 1); + ++MARK; + Move(MARK, MARK + 1, (SP - MARK) + 1, SV*); + ++SP; + } + PUSHMARK(MARK - 1); + *MARK = mg->mg_obj; + PUTBACK; + ENTER; + perl_call_method("PRINTF", G_SCALAR); + LEAVE; + SPAGAIN; + MARK = ORIGMARK + 1; + *MARK = *SP; + SP = MARK; + RETURN; + } + + sv = NEWSV(0,0); if (!(io = GvIO(gv))) { if (dowarn) { gv_fullname3(sv, gv, Nullch); @@ -1107,7 +1184,7 @@ PP(pp_prtf) PP(pp_sysopen) { - dSP; + djSP; GV *gv; SV *sv; char *tmps; @@ -1135,19 +1212,21 @@ PP(pp_sysopen) PP(pp_sysread) { - dSP; dMARK; dORIGMARK; dTARGET; + djSP; dMARK; dORIGMARK; dTARGET; int offset; GV *gv; IO *io; char *buffer; - int length; + SSize_t length; Sock_size_t bufsize; SV *bufsv; STRLEN blen; MAGIC *mg; gv = (GV*)*++MARK; - if (SvMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) { + if ((op->op_type == OP_READ || op->op_type == OP_SYSREAD) && + SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) + { SV *sv; PUSHMARK(MARK-1); @@ -1181,11 +1260,16 @@ PP(pp_sysread) goto say_undef; #ifdef HAS_SOCKET if (op->op_type == OP_RECV) { - bufsize = sizeof buf; + char namebuf[MAXPATHLEN]; +#if defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS) + bufsize = sizeof (struct sockaddr_in); +#else + bufsize = sizeof namebuf; +#endif buffer = SvGROW(bufsv, length+1); /* 'offset' means 'flags' here */ - length = recvfrom(PerlIO_fileno(IoIFP(io)), buffer, length, offset, - (struct sockaddr *)buf, &bufsize); + length = PerlSock_recvfrom(PerlIO_fileno(IoIFP(io)), buffer, length, offset, + (struct sockaddr *)namebuf, &bufsize); if (length < 0) RETPUSHUNDEF; SvCUR_set(bufsv, length); @@ -1196,7 +1280,7 @@ PP(pp_sysread) if (!(IoFLAGS(io) & IOf_UNTAINT)) SvTAINTED_on(bufsv); SP = ORIGMARK; - sv_setpvn(TARG, buf, bufsize); + sv_setpvn(TARG, namebuf, bufsize); PUSHs(TARG); RETURN; } @@ -1215,14 +1299,19 @@ PP(pp_sysread) Zero(buffer+bufsize, offset-bufsize, char); } if (op->op_type == OP_SYSREAD) { - length = read(PerlIO_fileno(IoIFP(io)), buffer+offset, length); + length = PerlLIO_read(PerlIO_fileno(IoIFP(io)), buffer+offset, length); } else #ifdef HAS_SOCKET__bad_code_maybe if (IoTYPE(io) == 's') { - bufsize = sizeof buf; - length = recvfrom(PerlIO_fileno(IoIFP(io)), buffer+offset, length, 0, - (struct sockaddr *)buf, &bufsize); + char namebuf[MAXPATHLEN]; +#if defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS) + bufsize = sizeof (struct sockaddr_in); +#else + bufsize = sizeof namebuf; +#endif + length = PerlSock_recvfrom(PerlIO_fileno(IoIFP(io)), buffer+offset, length, 0, + (struct sockaddr *)namebuf, &bufsize); } else #endif @@ -1252,7 +1341,7 @@ PP(pp_syswrite) PP(pp_send) { - dSP; dMARK; dORIGMARK; dTARGET; + djSP; dMARK; dORIGMARK; dTARGET; GV *gv; IO *io; int offset; @@ -1260,8 +1349,25 @@ PP(pp_send) char *buffer; int length; STRLEN blen; + MAGIC *mg; gv = (GV*)*++MARK; + if (op->op_type == OP_SYSWRITE && + SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) + { + SV *sv; + + PUSHMARK(MARK-1); + *MARK = mg->mg_obj; + ENTER; + perl_call_method("WRITE", G_SCALAR); + LEAVE; + SPAGAIN; + sv = POPs; + SP = ORIGMARK; + PUSHs(sv); + RETURN; + } if (!gv) goto say_undef; bufsv = *++MARK; @@ -1287,24 +1393,25 @@ PP(pp_send) if (-offset > blen) DIE("Offset outside string"); offset += blen; - } else if (offset >= blen) + } else if (offset >= blen && blen > 0) DIE("Offset outside string"); } else offset = 0; if (length > blen - offset) length = blen - offset; - length = write(PerlIO_fileno(IoIFP(io)), buffer+offset, length); + length = PerlLIO_write(PerlIO_fileno(IoIFP(io)), buffer+offset, length); } #ifdef HAS_SOCKET else if (SP > MARK) { char *sockbuf; STRLEN mlen; sockbuf = SvPVx(*++MARK, mlen); - length = sendto(PerlIO_fileno(IoIFP(io)), buffer, blen, length, + length = PerlSock_sendto(PerlIO_fileno(IoIFP(io)), buffer, blen, length, (struct sockaddr *)sockbuf, mlen); } else - length = send(PerlIO_fileno(IoIFP(io)), buffer, blen, length); + length = PerlSock_send(PerlIO_fileno(IoIFP(io)), buffer, blen, length); + #else else DIE(no_sock_func, "send"); @@ -1327,20 +1434,20 @@ PP(pp_recv) PP(pp_eof) { - dSP; + djSP; GV *gv; if (MAXARG <= 0) gv = last_in_gv; else gv = last_in_gv = (GV*)POPs; - PUSHs(!gv || do_eof(gv) ? &sv_yes : &sv_no); + PUSHs(boolSV(!gv || do_eof(gv))); RETURN; } PP(pp_tell) { - dSP; dTARGET; + djSP; dTARGET; GV *gv; if (MAXARG <= 0) @@ -1353,19 +1460,31 @@ PP(pp_tell) PP(pp_seek) { - dSP; + return pp_sysseek(ARGS); +} + +PP(pp_sysseek) +{ + djSP; GV *gv; int whence = POPi; long offset = POPl; gv = last_in_gv = (GV*)POPs; - PUSHs( do_seek(gv, offset, whence) ? &sv_yes : &sv_no ); + if (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 + : sv_2mortal(n ? newSViv((IV)n) + : newSVpv(zero_but_true, ZBTLEN))); + } RETURN; } PP(pp_truncate) { - dSP; + djSP; Off_t len = (Off_t)POPn; int result = 1; GV *tmpgv; @@ -1405,12 +1524,12 @@ PP(pp_truncate) #else { int tmpfd; - if ((tmpfd = open(name, O_RDWR)) < 0) + if ((tmpfd = PerlLIO_open(name, O_RDWR)) < 0) result = 0; else { if (my_chsize(tmpfd, len) < 0) result = 0; - close(tmpfd); + PerlLIO_close(tmpfd); } } #endif @@ -1433,12 +1552,12 @@ PP(pp_fcntl) PP(pp_ioctl) { - dSP; dTARGET; + djSP; dTARGET; SV *argsv = POPs; unsigned int func = U_I(POPn); int optype = op->op_type; char *s; - int retval; + IV retval; GV *gv = (GV*)POPs; IO *io = GvIOn(gv); @@ -1449,22 +1568,19 @@ PP(pp_ioctl) if (SvPOK(argsv) || !SvNIOK(argsv)) { STRLEN len; + STRLEN need; s = SvPV_force(argsv, len); - retval = IOCPARM_LEN(func); - if (len < retval) { - s = Sv_Grow(argsv, retval+1); - SvCUR_set(argsv, retval); + need = IOCPARM_LEN(func); + if (len < need) { + s = Sv_Grow(argsv, need + 1); + SvCUR_set(argsv, need); } s[SvCUR(argsv)] = 17; /* a little sanity check here */ } else { retval = SvIV(argsv); -#ifdef DOSISH - s = (char*)(long)retval; /* ouch */ -#else s = (char*)retval; /* ouch */ -#endif } TAINT_PROPER(optype == OP_IOCTL ? "ioctl" : "fcntl"); @@ -1500,14 +1616,14 @@ PP(pp_ioctl) PUSHi(retval); } else { - PUSHp("0 but true", 10); + PUSHp(zero_but_true, ZBTLEN); } RETURN; } PP(pp_flock) { - dSP; dTARGET; + djSP; dTARGET; I32 value; int argtype; GV *gv; @@ -1540,7 +1656,7 @@ PP(pp_flock) PP(pp_socket) { - dSP; + djSP; #ifdef HAS_SOCKET GV *gv; register IO *io; @@ -1561,7 +1677,7 @@ PP(pp_socket) do_close(gv, FALSE); TAINT_PROPER("socket"); - fd = socket(domain, type, protocol); + fd = PerlSock_socket(domain, type, protocol); if (fd < 0) RETPUSHUNDEF; IoIFP(io) = PerlIO_fdopen(fd, "r"); /* stdio gets confused about sockets */ @@ -1570,7 +1686,7 @@ PP(pp_socket) if (!IoIFP(io) || !IoOFP(io)) { if (IoIFP(io)) PerlIO_close(IoIFP(io)); if (IoOFP(io)) PerlIO_close(IoOFP(io)); - if (!IoIFP(io) && !IoOFP(io)) close(fd); + if (!IoIFP(io) && !IoOFP(io)) PerlLIO_close(fd); RETPUSHUNDEF; } @@ -1582,7 +1698,7 @@ PP(pp_socket) PP(pp_sockpair) { - dSP; + djSP; #ifdef HAS_SOCKETPAIR GV *gv1; GV *gv2; @@ -1606,7 +1722,7 @@ PP(pp_sockpair) do_close(gv2, FALSE); TAINT_PROPER("socketpair"); - if (socketpair(domain, type, protocol, fd) < 0) + if (PerlSock_socketpair(domain, type, protocol, fd) < 0) RETPUSHUNDEF; IoIFP(io1) = PerlIO_fdopen(fd[0], "r"); IoOFP(io1) = PerlIO_fdopen(fd[0], "w"); @@ -1617,10 +1733,10 @@ PP(pp_sockpair) if (!IoIFP(io1) || !IoOFP(io1) || !IoIFP(io2) || !IoOFP(io2)) { if (IoIFP(io1)) PerlIO_close(IoIFP(io1)); if (IoOFP(io1)) PerlIO_close(IoOFP(io1)); - if (!IoIFP(io1) && !IoOFP(io1)) close(fd[0]); + if (!IoIFP(io1) && !IoOFP(io1)) PerlLIO_close(fd[0]); if (IoIFP(io2)) PerlIO_close(IoIFP(io2)); if (IoOFP(io2)) PerlIO_close(IoOFP(io2)); - if (!IoIFP(io2) && !IoOFP(io2)) close(fd[1]); + if (!IoIFP(io2) && !IoOFP(io2)) PerlLIO_close(fd[1]); RETPUSHUNDEF; } @@ -1632,7 +1748,7 @@ PP(pp_sockpair) PP(pp_bind) { - dSP; + djSP; #ifdef HAS_SOCKET SV *addrsv = POPs; char *addr; @@ -1645,7 +1761,7 @@ PP(pp_bind) addr = SvPV(addrsv, len); TAINT_PROPER("bind"); - if (bind(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0) + if (PerlSock_bind(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0) RETPUSHYES; else RETPUSHUNDEF; @@ -1662,7 +1778,7 @@ nuts: PP(pp_connect) { - dSP; + djSP; #ifdef HAS_SOCKET SV *addrsv = POPs; char *addr; @@ -1675,7 +1791,7 @@ PP(pp_connect) addr = SvPV(addrsv, len); TAINT_PROPER("connect"); - if (connect(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0) + if (PerlSock_connect(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0) RETPUSHYES; else RETPUSHUNDEF; @@ -1692,7 +1808,7 @@ nuts: PP(pp_listen) { - dSP; + djSP; #ifdef HAS_SOCKET int backlog = POPi; GV *gv = (GV*)POPs; @@ -1701,7 +1817,7 @@ PP(pp_listen) if (!io || !IoIFP(io)) goto nuts; - if (listen(PerlIO_fileno(IoIFP(io)), backlog) >= 0) + if (PerlSock_listen(PerlIO_fileno(IoIFP(io)), backlog) >= 0) RETPUSHYES; else RETPUSHUNDEF; @@ -1718,7 +1834,7 @@ nuts: PP(pp_accept) { - dSP; dTARGET; + djSP; dTARGET; #ifdef HAS_SOCKET GV *ngv; GV *ggv; @@ -1744,7 +1860,7 @@ PP(pp_accept) if (IoIFP(nstio)) do_close(ngv, FALSE); - fd = accept(PerlIO_fileno(IoIFP(gstio)), (struct sockaddr *)&saddr, &len); + fd = PerlSock_accept(PerlIO_fileno(IoIFP(gstio)), (struct sockaddr *)&saddr, &len); if (fd < 0) goto badexit; IoIFP(nstio) = PerlIO_fdopen(fd, "r"); @@ -1753,7 +1869,7 @@ PP(pp_accept) if (!IoIFP(nstio) || !IoOFP(nstio)) { if (IoIFP(nstio)) PerlIO_close(IoIFP(nstio)); if (IoOFP(nstio)) PerlIO_close(IoOFP(nstio)); - if (!IoIFP(nstio) && !IoOFP(nstio)) close(fd); + if (!IoIFP(nstio) && !IoOFP(nstio)) PerlLIO_close(fd); goto badexit; } @@ -1775,7 +1891,7 @@ badexit: PP(pp_shutdown) { - dSP; dTARGET; + djSP; dTARGET; #ifdef HAS_SOCKET int how = POPi; GV *gv = (GV*)POPs; @@ -1784,7 +1900,7 @@ PP(pp_shutdown) if (!io || !IoIFP(io)) goto nuts; - PUSHi( shutdown(PerlIO_fileno(IoIFP(io)), how) >= 0 ); + PUSHi( PerlSock_shutdown(PerlIO_fileno(IoIFP(io)), how) >= 0 ); RETURN; nuts: @@ -1808,7 +1924,7 @@ PP(pp_gsockopt) PP(pp_ssockopt) { - dSP; + djSP; #ifdef HAS_SOCKET int optype = op->op_type; SV *sv; @@ -1839,7 +1955,7 @@ PP(pp_ssockopt) SvCUR_set(sv,256); *SvEND(sv) ='\0'; len = SvCUR(sv); - if (getsockopt(fd, lvl, optname, SvPVX(sv), &len) < 0) + if (PerlSock_getsockopt(fd, lvl, optname, SvPVX(sv), &len) < 0) goto nuts2; SvCUR_set(sv, len); *SvEND(sv) ='\0'; @@ -1857,7 +1973,7 @@ PP(pp_ssockopt) buf = (char*)&aint; len = sizeof(int); } - if (setsockopt(fd, lvl, optname, buf, len) < 0) + if (PerlSock_setsockopt(fd, lvl, optname, buf, len) < 0) goto nuts2; PUSHs(&sv_yes); } @@ -1888,7 +2004,7 @@ PP(pp_getsockname) PP(pp_getpeername) { - dSP; + djSP; #ifdef HAS_SOCKET int optype = op->op_type; SV *sv; @@ -1908,12 +2024,23 @@ PP(pp_getpeername) fd = PerlIO_fileno(IoIFP(io)); switch (optype) { case OP_GETSOCKNAME: - if (getsockname(fd, (struct sockaddr *)SvPVX(sv), &len) < 0) + if (PerlSock_getsockname(fd, (struct sockaddr *)SvPVX(sv), &len) < 0) goto nuts2; break; case OP_GETPEERNAME: - if (getpeername(fd, (struct sockaddr *)SvPVX(sv), &len) < 0) + if (PerlSock_getpeername(fd, (struct sockaddr *)SvPVX(sv), &len) < 0) goto nuts2; +#if defined(VMS_DO_SOCKETS) && defined (DECCRTL_SOCKETS) + { + static const char nowhere[] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + /* If the call succeeded, make sure we don't have a zeroed port/addr */ + if (((struct sockaddr *)SvPVX(sv))->sa_family == AF_INET && + !memcmp((char *)SvPVX(sv) + sizeof(u_short), nowhere, + sizeof(u_short) + sizeof(struct in_addr))) { + goto nuts2; + } + } +#endif break; } #ifdef BOGUS_GETNAME_RETURN @@ -1948,8 +2075,9 @@ PP(pp_lstat) PP(pp_stat) { - dSP; + djSP; GV *tmpgv; + I32 gimme; I32 max = 13; if (op->op_flags & OPf_REF) { @@ -1960,7 +2088,7 @@ PP(pp_stat) statgv = tmpgv; sv_setpv(statname, ""); laststatval = (GvIO(tmpgv) && IoIFP(GvIOp(tmpgv)) - ? Fstat(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), &statcache) : -1); + ? PerlLIO_fstat(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), &statcache) : -1); } if (laststatval < 0) max = 0; @@ -1980,10 +2108,10 @@ PP(pp_stat) #ifdef HAS_LSTAT laststype = op->op_type; if (op->op_type == OP_LSTAT) - laststatval = lstat(SvPV(statname, na), &statcache); + laststatval = PerlLIO_lstat(SvPV(statname, na), &statcache); else #endif - laststatval = Stat(SvPV(statname, na), &statcache); + laststatval = PerlLIO_stat(SvPV(statname, na), &statcache); if (laststatval < 0) { if (dowarn && strchr(SvPV(statname, na), '\n')) warn(warn_nl, "stat"); @@ -1991,17 +2119,15 @@ PP(pp_stat) } } - if (GIMME != G_ARRAY) { - EXTEND(SP, 1); - if (max) - RETPUSHYES; - else - RETPUSHUNDEF; + gimme = GIMME_V; + if (gimme != G_ARRAY) { + if (gimme != G_VOID) + XPUSHs(boolSV(max)); + RETURN; } 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))); @@ -2037,7 +2163,7 @@ PP(pp_stat) PP(pp_ftrread) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (cando(S_IRUSR, 0, &statcache)) @@ -2048,7 +2174,7 @@ PP(pp_ftrread) PP(pp_ftrwrite) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (cando(S_IWUSR, 0, &statcache)) @@ -2059,7 +2185,7 @@ PP(pp_ftrwrite) PP(pp_ftrexec) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (cando(S_IXUSR, 0, &statcache)) @@ -2070,7 +2196,7 @@ PP(pp_ftrexec) PP(pp_fteread) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (cando(S_IRUSR, 1, &statcache)) @@ -2081,7 +2207,7 @@ PP(pp_fteread) PP(pp_ftewrite) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (cando(S_IWUSR, 1, &statcache)) @@ -2092,7 +2218,7 @@ PP(pp_ftewrite) PP(pp_fteexec) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (cando(S_IXUSR, 1, &statcache)) @@ -2103,7 +2229,7 @@ PP(pp_fteexec) PP(pp_ftis) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; RETPUSHYES; @@ -2117,7 +2243,7 @@ PP(pp_fteowned) PP(pp_ftrowned) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (statcache.st_uid == (op->op_type == OP_FTEOWNED ? euid : uid) ) @@ -2128,7 +2254,7 @@ PP(pp_ftrowned) PP(pp_ftzero) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (!statcache.st_size) @@ -2139,7 +2265,7 @@ PP(pp_ftzero) PP(pp_ftsize) { I32 result = my_stat(ARGS); - dSP; dTARGET; + djSP; dTARGET; if (result < 0) RETPUSHUNDEF; PUSHi(statcache.st_size); @@ -2149,7 +2275,7 @@ PP(pp_ftsize) PP(pp_ftmtime) { I32 result = my_stat(ARGS); - dSP; dTARGET; + djSP; dTARGET; if (result < 0) RETPUSHUNDEF; PUSHn( ((I32)basetime - (I32)statcache.st_mtime) / 86400.0 ); @@ -2159,7 +2285,7 @@ PP(pp_ftmtime) PP(pp_ftatime) { I32 result = my_stat(ARGS); - dSP; dTARGET; + djSP; dTARGET; if (result < 0) RETPUSHUNDEF; PUSHn( ((I32)basetime - (I32)statcache.st_atime) / 86400.0 ); @@ -2169,7 +2295,7 @@ PP(pp_ftatime) PP(pp_ftctime) { I32 result = my_stat(ARGS); - dSP; dTARGET; + djSP; dTARGET; if (result < 0) RETPUSHUNDEF; PUSHn( ((I32)basetime - (I32)statcache.st_ctime) / 86400.0 ); @@ -2179,7 +2305,7 @@ PP(pp_ftctime) PP(pp_ftsock) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (S_ISSOCK(statcache.st_mode)) @@ -2190,7 +2316,7 @@ PP(pp_ftsock) PP(pp_ftchr) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (S_ISCHR(statcache.st_mode)) @@ -2201,7 +2327,7 @@ PP(pp_ftchr) PP(pp_ftblk) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (S_ISBLK(statcache.st_mode)) @@ -2212,7 +2338,7 @@ PP(pp_ftblk) PP(pp_ftfile) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (S_ISREG(statcache.st_mode)) @@ -2223,7 +2349,7 @@ PP(pp_ftfile) PP(pp_ftdir) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (S_ISDIR(statcache.st_mode)) @@ -2234,7 +2360,7 @@ PP(pp_ftdir) PP(pp_ftpipe) { I32 result = my_stat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (S_ISFIFO(statcache.st_mode)) @@ -2245,7 +2371,7 @@ PP(pp_ftpipe) PP(pp_ftlink) { I32 result = my_lstat(ARGS); - dSP; + djSP; if (result < 0) RETPUSHUNDEF; if (S_ISLNK(statcache.st_mode)) @@ -2255,7 +2381,7 @@ PP(pp_ftlink) PP(pp_ftsuid) { - dSP; + djSP; #ifdef S_ISUID I32 result = my_stat(ARGS); SPAGAIN; @@ -2269,7 +2395,7 @@ PP(pp_ftsuid) PP(pp_ftsgid) { - dSP; + djSP; #ifdef S_ISGID I32 result = my_stat(ARGS); SPAGAIN; @@ -2283,7 +2409,7 @@ PP(pp_ftsgid) PP(pp_ftsvtx) { - dSP; + djSP; #ifdef S_ISVTX I32 result = my_stat(ARGS); SPAGAIN; @@ -2297,23 +2423,27 @@ PP(pp_ftsvtx) PP(pp_fttty) { - dSP; + djSP; int fd; GV *gv; - char *tmps; - if (op->op_flags & OPf_REF) { + char *tmps = Nullch; + + if (op->op_flags & OPf_REF) gv = cGVOP->op_gv; - tmps = ""; - } + else if (isGV(TOPs)) + gv = (GV*)POPs; + else if (SvROK(TOPs) && isGV(SvRV(TOPs))) + gv = (GV*)SvRV(POPs); else gv = gv_fetchpv(tmps = POPp, FALSE, SVt_PVIO); + if (GvIO(gv) && IoIFP(GvIOp(gv))) fd = PerlIO_fileno(IoIFP(GvIOp(gv))); - else if (isDIGIT(*tmps)) + else if (tmps && isDIGIT(*tmps)) fd = atoi(tmps); else RETPUSHUNDEF; - if (isatty(fd)) + if (PerlLIO_isatty(fd)) RETPUSHYES; RETPUSHNO; } @@ -2328,7 +2458,7 @@ PP(pp_fttty) PP(pp_fttext) { - dSP; + djSP; I32 i; I32 len; I32 odd = 0; @@ -2366,7 +2496,7 @@ PP(pp_fttext) if (io && IoIFP(io)) { if (! PerlIO_has_base(IoIFP(io))) DIE("-T and -B not implemented on filehandles"); - laststatval = Fstat(PerlIO_fileno(IoIFP(io)), &statcache); + laststatval = PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &statcache); if (laststatval < 0) RETPUSHUNDEF; if (S_ISDIR(statcache.st_mode)) /* handle NFS glitch */ @@ -2402,20 +2532,20 @@ PP(pp_fttext) laststatval = -1; sv_setpv(statname, SvPV(sv, na)); #ifdef HAS_OPEN3 - i = open(SvPV(sv, na), O_RDONLY, 0); + i = PerlLIO_open3(SvPV(sv, na), O_RDONLY, 0); #else - i = open(SvPV(sv, na), 0); + i = PerlLIO_open(SvPV(sv, na), 0); #endif if (i < 0) { if (dowarn && strchr(SvPV(sv, na), '\n')) warn(warn_nl, "open"); RETPUSHUNDEF; } - laststatval = Fstat(i, &statcache); + laststatval = PerlLIO_fstat(i, &statcache); if (laststatval < 0) RETPUSHUNDEF; - len = read(i, tbuf, 512); - (void)close(i); + len = PerlLIO_read(i, tbuf, 512); + (void)PerlLIO_close(i); if (len <= 0) { if (S_ISDIR(statcache.st_mode) && op->op_type == OP_FTTEXT) RETPUSHNO; /* special case NFS directories */ @@ -2455,7 +2585,7 @@ PP(pp_ftbinary) PP(pp_chdir) { - dSP; dTARGET; + djSP; dTARGET; char *tmps; SV **svp; @@ -2474,7 +2604,7 @@ PP(pp_chdir) tmps = SvPV(*svp, na); } TAINT_PROPER("chdir"); - PUSHi( chdir(tmps) >= 0 ); + PUSHi( PerlDir_chdir(tmps) >= 0 ); #ifdef VMS /* Clear the DEFAULT element of ENV so we'll get the new value * in the future. */ @@ -2485,7 +2615,7 @@ PP(pp_chdir) PP(pp_chown) { - dSP; dMARK; dTARGET; + djSP; dMARK; dTARGET; I32 value; #ifdef HAS_CHOWN value = (I32)apply(op->op_type, MARK, SP); @@ -2499,7 +2629,7 @@ PP(pp_chown) PP(pp_chroot) { - dSP; dTARGET; + djSP; dTARGET; char *tmps; #ifdef HAS_CHROOT tmps = POPp; @@ -2513,7 +2643,7 @@ PP(pp_chroot) PP(pp_unlink) { - dSP; dMARK; dTARGET; + djSP; dMARK; dTARGET; I32 value; value = (I32)apply(op->op_type, MARK, SP); SP = MARK; @@ -2523,7 +2653,7 @@ PP(pp_unlink) PP(pp_chmod) { - dSP; dMARK; dTARGET; + djSP; dMARK; dTARGET; I32 value; value = (I32)apply(op->op_type, MARK, SP); SP = MARK; @@ -2533,7 +2663,7 @@ PP(pp_chmod) PP(pp_utime) { - dSP; dMARK; dTARGET; + djSP; dMARK; dTARGET; I32 value; value = (I32)apply(op->op_type, MARK, SP); SP = MARK; @@ -2543,7 +2673,7 @@ PP(pp_utime) PP(pp_rename) { - dSP; dTARGET; + djSP; dTARGET; int anum; char *tmps2 = POPp; @@ -2552,11 +2682,11 @@ PP(pp_rename) #ifdef HAS_RENAME anum = rename(tmps, tmps2); #else - if (!(anum = Stat(tmps, &statbuf))) { + if (!(anum = PerlLIO_stat(tmps, &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 (euid || PerlLIO_stat(tmps2, &statbuf) < 0 || !S_ISDIR(statbuf.st_mode)) (void)UNLINK(tmps2); if (!(anum = link(tmps, tmps2))) anum = UNLINK(tmps); @@ -2569,7 +2699,7 @@ PP(pp_rename) PP(pp_link) { - dSP; dTARGET; + djSP; dTARGET; #ifdef HAS_LINK char *tmps2 = POPp; char *tmps = SvPV(TOPs, na); @@ -2583,7 +2713,7 @@ PP(pp_link) PP(pp_symlink) { - dSP; dTARGET; + djSP; dTARGET; #ifdef HAS_SYMLINK char *tmps2 = POPp; char *tmps = SvPV(TOPs, na); @@ -2597,10 +2727,15 @@ PP(pp_symlink) PP(pp_readlink) { - dSP; dTARGET; + djSP; dTARGET; #ifdef HAS_SYMLINK char *tmps; + char buf[MAXPATHLEN]; int len; + +#ifndef INCOMPLETE_TAINTS + TAINT; +#endif tmps = POPp; len = readlink(tmps, buf, sizeof buf); EXTEND(SP, 1); @@ -2634,14 +2769,14 @@ char *filename; *s++ = *filename++; } strcpy(s, " 2>&1"); - myfp = my_popen(cmdline, "r"); + myfp = PerlProc_popen(cmdline, "r"); Safefree(cmdline); if (myfp) { SV *tmpsv = sv_newmortal(); /* Need to save/restore 'rs' ?? */ s = sv_gets(tmpsv, myfp, 0); - (void)my_pclose(myfp); + (void)PerlProc_pclose(myfp); if (s != Nullch) { int e; for (e = 1; @@ -2688,7 +2823,7 @@ char *filename; return 0; } else { /* some mkdirs return no failure indication */ - anum = (Stat(save_filename, &statbuf) >= 0); + anum = (PerlLIO_stat(save_filename, &statbuf) >= 0); if (op->op_type == OP_RMDIR) anum = !anum; if (anum) @@ -2705,7 +2840,7 @@ char *filename; PP(pp_mkdir) { - dSP; dTARGET; + djSP; dTARGET; int mode = POPi; #ifndef HAS_MKDIR int oldumask; @@ -2714,25 +2849,25 @@ PP(pp_mkdir) TAINT_PROPER("mkdir"); #ifdef HAS_MKDIR - SETi( mkdir(tmps, mode) >= 0 ); + SETi( PerlDir_mkdir(tmps, mode) >= 0 ); #else SETi( dooneliner("mkdir", tmps) ); - oldumask = umask(0); - umask(oldumask); - chmod(tmps, (mode & ~oldumask) & 0777); + oldumask = PerlLIO_umask(0); + PerlLIO_umask(oldumask); + PerlLIO_chmod(tmps, (mode & ~oldumask) & 0777); #endif RETURN; } PP(pp_rmdir) { - dSP; dTARGET; + djSP; dTARGET; char *tmps; tmps = POPp; TAINT_PROPER("rmdir"); #ifdef HAS_RMDIR - XPUSHi( rmdir(tmps) >= 0 ); + XPUSHi( PerlDir_rmdir(tmps) >= 0 ); #else XPUSHi( dooneliner("rmdir", tmps) ); #endif @@ -2743,7 +2878,7 @@ PP(pp_rmdir) PP(pp_open_dir) { - dSP; + djSP; #if defined(Direntry_t) && defined(HAS_READDIR) char *dirname = POPp; GV *gv = (GV*)POPs; @@ -2753,8 +2888,8 @@ PP(pp_open_dir) goto nope; if (IoDIRP(io)) - closedir(IoDIRP(io)); - if (!(IoDIRP(io) = opendir(dirname))) + PerlDir_close(IoDIRP(io)); + if (!(IoDIRP(io) = PerlDir_open(dirname))) goto nope; RETPUSHYES; @@ -2769,7 +2904,7 @@ nope: PP(pp_readdir) { - dSP; + djSP; #if defined(Direntry_t) && defined(HAS_READDIR) #ifndef I_DIRENT Direntry_t *readdir _((DIR *)); @@ -2777,28 +2912,37 @@ PP(pp_readdir) register Direntry_t *dp; GV *gv = (GV*)POPs; register IO *io = GvIOn(gv); + SV *sv; if (!io || !IoDIRP(io)) goto nope; if (GIMME == G_ARRAY) { /*SUPPRESS 560*/ - while (dp = (Direntry_t *)readdir(IoDIRP(io))) { + while (dp = (Direntry_t *)PerlDir_read(IoDIRP(io))) { #ifdef DIRNAMLEN - XPUSHs(sv_2mortal(newSVpv(dp->d_name, dp->d_namlen))); + sv = newSVpv(dp->d_name, dp->d_namlen); #else - XPUSHs(sv_2mortal(newSVpv(dp->d_name, 0))); + sv = newSVpv(dp->d_name, 0); #endif +#ifndef INCOMPLETE_TAINTS + SvTAINTED_on(sv); +#endif + XPUSHs(sv_2mortal(sv)); } } else { - if (!(dp = (Direntry_t *)readdir(IoDIRP(io)))) + if (!(dp = (Direntry_t *)PerlDir_read(IoDIRP(io)))) goto nope; #ifdef DIRNAMLEN - XPUSHs(sv_2mortal(newSVpv(dp->d_name, dp->d_namlen))); + sv = newSVpv(dp->d_name, dp->d_namlen); #else - XPUSHs(sv_2mortal(newSVpv(dp->d_name, 0))); + sv = newSVpv(dp->d_name, 0); +#endif +#ifndef INCOMPLETE_TAINTS + SvTAINTED_on(sv); #endif + XPUSHs(sv_2mortal(sv)); } RETURN; @@ -2816,18 +2960,18 @@ nope: PP(pp_telldir) { - dSP; dTARGET; + djSP; dTARGET; #if defined(HAS_TELLDIR) || defined(telldir) -#if !defined(telldir) && !defined(HAS_TELLDIR_PROTOTYPE) +# ifdef NEED_TELLDIR_PROTO /* XXX does _anyone_ need this? --AD 2/20/1998 */ long telldir _((DIR *)); -#endif +# endif GV *gv = (GV*)POPs; register IO *io = GvIOn(gv); if (!io || !IoDIRP(io)) goto nope; - PUSHi( telldir(IoDIRP(io)) ); + PUSHi( PerlDir_tell(IoDIRP(io)) ); RETURN; nope: if (!errno) @@ -2840,7 +2984,7 @@ nope: PP(pp_seekdir) { - dSP; + djSP; #if defined(HAS_SEEKDIR) || defined(seekdir) long along = POPl; GV *gv = (GV*)POPs; @@ -2849,7 +2993,7 @@ PP(pp_seekdir) if (!io || !IoDIRP(io)) goto nope; - (void)seekdir(IoDIRP(io), along); + (void)PerlDir_seek(IoDIRP(io), along); RETPUSHYES; nope: @@ -2863,7 +3007,7 @@ nope: PP(pp_rewinddir) { - dSP; + djSP; #if defined(HAS_REWINDDIR) || defined(rewinddir) GV *gv = (GV*)POPs; register IO *io = GvIOn(gv); @@ -2871,7 +3015,7 @@ PP(pp_rewinddir) if (!io || !IoDIRP(io)) goto nope; - (void)rewinddir(IoDIRP(io)); + (void)PerlDir_rewind(IoDIRP(io)); RETPUSHYES; nope: if (!errno) @@ -2884,7 +3028,7 @@ nope: PP(pp_closedir) { - dSP; + djSP; #if defined(Direntry_t) && defined(HAS_READDIR) GV *gv = (GV*)POPs; register IO *io = GvIOn(gv); @@ -2893,9 +3037,9 @@ PP(pp_closedir) goto nope; #ifdef VOID_CLOSEDIR - closedir(IoDIRP(io)); + PerlDir_close(IoDIRP(io)); #else - if (closedir(IoDIRP(io)) < 0) { + if (PerlDir_close(IoDIRP(io)) < 0) { IoDIRP(io) = 0; /* Don't try to close again--coredumps on SysV */ goto nope; } @@ -2917,7 +3061,7 @@ nope: PP(pp_fork) { #ifdef HAS_FORK - dSP; dTARGET; + djSP; dTARGET; int childpid; GV *tmpgv; @@ -2940,8 +3084,8 @@ PP(pp_fork) PP(pp_wait) { -#if !defined(DOSISH) || defined(OS2) - dSP; dTARGET; +#if !defined(DOSISH) || defined(OS2) || defined(WIN32) + djSP; dTARGET; int childpid; int argflags; @@ -2956,8 +3100,8 @@ PP(pp_wait) PP(pp_waitpid) { -#if !defined(DOSISH) || defined(OS2) - dSP; dTARGET; +#if !defined(DOSISH) || defined(OS2) || defined(WIN32) + djSP; dTARGET; int childpid; int optype; int argflags; @@ -2969,13 +3113,13 @@ PP(pp_waitpid) SETi(childpid); RETURN; #else - DIE(no_func, "Unsupported function wait"); + DIE(no_func, "Unsupported function waitpid"); #endif } PP(pp_system) { - dSP; dMARK; dORIGMARK; dTARGET; + djSP; dMARK; dORIGMARK; dTARGET; I32 value; int childpid; int result; @@ -3022,14 +3166,14 @@ PP(pp_system) else { value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), na)); } - _exit(-1); + PerlProc__exit(-1); #else /* ! FORK or VMS or OS/2 */ if (op->op_flags & OPf_STACKED) { SV *really = *++MARK; - value = (I32)do_aspawn(really, MARK, SP); + value = (I32)do_aspawn(really, (void **)MARK, (void **)SP); } else if (SP - MARK != 1) - value = (I32)do_aspawn(Nullsv, MARK, SP); + value = (I32)do_aspawn(Nullsv, (void **)MARK, (void **)SP); else { value = (I32)do_spawn(SvPVx(sv_mortalcopy(*SP), na)); } @@ -3043,7 +3187,7 @@ PP(pp_system) PP(pp_exec) { - dSP; dMARK; dORIGMARK; dTARGET; + djSP; dMARK; dORIGMARK; dTARGET; I32 value; if (op->op_flags & OPf_STACKED) { @@ -3075,7 +3219,7 @@ PP(pp_exec) PP(pp_kill) { - dSP; dMARK; dTARGET; + djSP; dMARK; dTARGET; I32 value; #ifdef HAS_KILL value = (I32)apply(op->op_type, MARK, SP); @@ -3090,7 +3234,7 @@ PP(pp_kill) PP(pp_getppid) { #ifdef HAS_GETPPID - dSP; dTARGET; + djSP; dTARGET; XPUSHi( getppid() ); RETURN; #else @@ -3101,7 +3245,7 @@ PP(pp_getppid) PP(pp_getpgrp) { #ifdef HAS_GETPGRP - dSP; dTARGET; + djSP; dTARGET; int pid; I32 value; @@ -3126,7 +3270,7 @@ PP(pp_getpgrp) PP(pp_setpgrp) { #ifdef HAS_SETPGRP - dSP; dTARGET; + djSP; dTARGET; int pgrp; int pid; if (MAXARG < 2) { @@ -3142,7 +3286,7 @@ PP(pp_setpgrp) #ifdef BSD_SETPGRP SETi( BSD_SETPGRP(pid, pgrp) >= 0 ); #else - if ((pgrp != 0 && pgrp != getpid())) || (pid != 0 && pid != getpid())) + if ((pgrp != 0 && pgrp != getpid()) || (pid != 0 && pid != getpid())) DIE("POSIX setpgrp can't take an argument"); SETi( setpgrp() >= 0 ); #endif /* USE_BSDPGRP */ @@ -3154,7 +3298,7 @@ PP(pp_setpgrp) PP(pp_getpriority) { - dSP; dTARGET; + djSP; dTARGET; int which; int who; #ifdef HAS_GETPRIORITY @@ -3169,7 +3313,7 @@ PP(pp_getpriority) PP(pp_setpriority) { - dSP; dTARGET; + djSP; dTARGET; int which; int who; int niceval; @@ -3189,7 +3333,7 @@ PP(pp_setpriority) PP(pp_time) { - dSP; dTARGET; + djSP; dTARGET; #ifdef BIG_TIME XPUSHn( time(Null(Time_t*)) ); #else @@ -3216,7 +3360,7 @@ PP(pp_time) PP(pp_tms) { - dSP; + djSP; #ifndef HAS_TIMES DIE("times not implemented"); @@ -3248,7 +3392,7 @@ PP(pp_localtime) PP(pp_gmtime) { - dSP; + djSP; Time_t when; struct tm *tmbuf; static char *dayname[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; @@ -3273,18 +3417,18 @@ PP(pp_gmtime) EXTEND_MORTAL(9); if (GIMME != G_ARRAY) { dTARGET; - char mybuf[30]; + SV *tsv; if (!tmbuf) RETPUSHUNDEF; - sprintf(mybuf, "%s %s %2d %02d:%02d:%02d %d", - dayname[tmbuf->tm_wday], - monname[tmbuf->tm_mon], - tmbuf->tm_mday, - tmbuf->tm_hour, - tmbuf->tm_min, - tmbuf->tm_sec, - tmbuf->tm_year + 1900); - PUSHp(mybuf, strlen(mybuf)); + tsv = newSVpvf("%s %s %2d %02d:%02d:%02d %d", + dayname[tmbuf->tm_wday], + monname[tmbuf->tm_mon], + tmbuf->tm_mday, + tmbuf->tm_hour, + tmbuf->tm_min, + tmbuf->tm_sec, + tmbuf->tm_year + 1900); + PUSHs(sv_2mortal(tsv)); } else if (tmbuf) { PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_sec))); @@ -3302,7 +3446,7 @@ PP(pp_gmtime) PP(pp_alarm) { - dSP; dTARGET; + djSP; dTARGET; int anum; #ifdef HAS_ALARM anum = POPi; @@ -3319,7 +3463,7 @@ PP(pp_alarm) PP(pp_sleep) { - dSP; dTARGET; + djSP; dTARGET; I32 duration; Time_t lasttime; Time_t when; @@ -3356,7 +3500,7 @@ PP(pp_shmread) PP(pp_shmwrite) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) - dSP; dMARK; dTARGET; + djSP; dMARK; dTARGET; I32 value = (I32)(do_shmio(op->op_type, MARK, SP) >= 0); SP = MARK; PUSHi(value); @@ -3381,7 +3525,7 @@ PP(pp_msgctl) PP(pp_msgsnd) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) - dSP; dMARK; dTARGET; + djSP; dMARK; dTARGET; I32 value = (I32)(do_msgsnd(MARK, SP) >= 0); SP = MARK; PUSHi(value); @@ -3394,7 +3538,7 @@ PP(pp_msgsnd) PP(pp_msgrcv) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) - dSP; dMARK; dTARGET; + djSP; dMARK; dTARGET; I32 value = (I32)(do_msgrcv(MARK, SP) >= 0); SP = MARK; PUSHi(value); @@ -3409,7 +3553,7 @@ PP(pp_msgrcv) PP(pp_semget) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) - dSP; dMARK; dTARGET; + djSP; dMARK; dTARGET; int anum = do_ipcget(op->op_type, MARK, SP); SP = MARK; if (anum == -1) @@ -3424,7 +3568,7 @@ PP(pp_semget) PP(pp_semctl) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) - dSP; dMARK; dTARGET; + djSP; dMARK; dTARGET; int anum = do_ipcctl(op->op_type, MARK, SP); SP = MARK; if (anum == -1) @@ -3433,7 +3577,7 @@ PP(pp_semctl) PUSHi(anum); } else { - PUSHp("0 but true",10); + PUSHp(zero_but_true, ZBTLEN); } RETURN; #else @@ -3444,7 +3588,7 @@ PP(pp_semctl) PP(pp_semop) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) - dSP; dMARK; dTARGET; + djSP; dMARK; dTARGET; I32 value = (I32)(do_semop(MARK, SP) >= 0); SP = MARK; PUSHi(value); @@ -3458,7 +3602,7 @@ PP(pp_semop) PP(pp_ghbyname) { -#ifdef HAS_SOCKET +#ifdef HAS_GETHOSTBYNAME return pp_ghostent(ARGS); #else DIE(no_sock_func, "gethostbyname"); @@ -3467,7 +3611,7 @@ PP(pp_ghbyname) PP(pp_ghbyaddr) { -#ifdef HAS_SOCKET +#ifdef HAS_GETHOSTBYADDR return pp_ghostent(ARGS); #else DIE(no_sock_func, "gethostbyaddr"); @@ -3476,36 +3620,43 @@ PP(pp_ghbyaddr) PP(pp_ghostent) { - dSP; -#ifdef HAS_SOCKET + djSP; +#if defined(HAS_GETHOSTBYNAME) || defined(HAS_GETHOSTBYADDR) || defined(HAS_GETHOSTENT) I32 which = op->op_type; register char **elem; register SV *sv; - struct hostent *gethostbyname(); - struct hostent *gethostbyaddr(); -#ifdef HAS_GETHOSTENT - struct hostent *gethostent(); +#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); + struct hostent *PerlSock_gethostent(void); #endif struct hostent *hent; unsigned long len; EXTEND(SP, 10); - if (which == OP_GHBYNAME) { - hent = gethostbyname(POPp); - } + 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; - char *addr = SvPV(addrsv, addrlen); + Netdb_host_t addr = (Netdb_host_t) SvPV(addrsv, addrlen); - hent = gethostbyaddr(addr, addrlen, addrtype); + hent = PerlSock_gethostbyaddr(addr, (Netdb_hlen_t) addrlen, addrtype); +#else + DIE(no_sock_func, "gethostbyaddr"); +#endif } else #ifdef HAS_GETHOSTENT - hent = gethostent(); + hent = PerlSock_gethostent(); #else - DIE("gethostent not implemented"); + DIE(no_sock_func, "gethostent"); #endif #ifdef HOST_NOT_FOUND @@ -3559,7 +3710,7 @@ PP(pp_ghostent) PP(pp_gnbyname) { -#ifdef HAS_SOCKET +#ifdef HAS_GETNETBYNAME return pp_gnetent(ARGS); #else DIE(no_sock_func, "getnetbyname"); @@ -3568,7 +3719,7 @@ PP(pp_gnbyname) PP(pp_gnbyaddr) { -#ifdef HAS_SOCKET +#ifdef HAS_GETNETBYADDR return pp_gnetent(ARGS); #else DIE(no_sock_func, "getnetbyaddr"); @@ -3577,25 +3728,39 @@ PP(pp_gnbyaddr) PP(pp_gnetent) { - dSP; -#ifdef HAS_SOCKET + djSP; +#if defined(HAS_GETNETBYNAME) || defined(HAS_GETNETBYADDR) || defined(HAS_GETNETENT) I32 which = op->op_type; register char **elem; register SV *sv; - struct netent *getnetbyname(); - struct netent *getnetbyaddr(); - struct netent *getnetent(); +#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; - unsigned long addr = U_L(POPn); - nent = getnetbyaddr((long)addr, addrtype); + Netdb_net_t addr = (Netdb_net_t) U_L(POPn); + 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) { @@ -3613,7 +3778,7 @@ PP(pp_gnetent) PUSHs(sv = sv_mortalcopy(&sv_no)); sv_setpv(sv, nent->n_name); PUSHs(sv = sv_mortalcopy(&sv_no)); - for (elem = nent->n_aliases; *elem; elem++) { + for (elem = nent->n_aliases; elem && *elem; elem++) { sv_catpv(sv, *elem); if (elem[1]) sv_catpvn(sv, " ", 1); @@ -3632,7 +3797,7 @@ PP(pp_gnetent) PP(pp_gpbyname) { -#ifdef HAS_SOCKET +#ifdef HAS_GETPROTOBYNAME return pp_gprotoent(ARGS); #else DIE(no_sock_func, "getprotobyname"); @@ -3641,7 +3806,7 @@ PP(pp_gpbyname) PP(pp_gpbynumber) { -#ifdef HAS_SOCKET +#ifdef HAS_GETPROTOBYNUMBER return pp_gprotoent(ARGS); #else DIE(no_sock_func, "getprotobynumber"); @@ -3650,22 +3815,36 @@ PP(pp_gpbynumber) PP(pp_gprotoent) { - dSP; -#ifdef HAS_SOCKET + djSP; +#if defined(HAS_GETPROTOBYNAME) || defined(HAS_GETPROTOBYNUMBER) || defined(HAS_GETPROTOENT) I32 which = op->op_type; register char **elem; - register SV *sv; - struct protoent *getprotobyname(); - struct protoent *getprotobynumber(); - struct protoent *getprotoent(); + register SV *sv; +#ifndef HAS_GETPROTO_PROTOS /* XXX Do we need individual probes? */ + struct protoent *PerlSock_getprotobyname(Netdb_name_t); + struct protoent *PerlSock_getprotobynumber(int); + struct protoent *PerlSock_getprotoent(void); +#endif struct protoent *pent; if (which == OP_GPBYNAME) - pent = getprotobyname(POPp); +#ifdef HAS_GETPROTOBYNAME + pent = PerlSock_getprotobyname(POPp); +#else + DIE(no_sock_func, "getprotobyname"); +#endif else if (which == OP_GPBYNUMBER) - pent = getprotobynumber(POPi); +#ifdef HAS_GETPROTOBYNUMBER + pent = PerlSock_getprotobynumber(POPi); +#else + DIE(no_sock_func, "getprotobynumber"); +#endif else - pent = getprotoent(); +#ifdef HAS_GETPROTOENT + pent = PerlSock_getprotoent(); +#else + DIE(no_sock_func, "getprotoent"); +#endif EXTEND(SP, 3); if (GIMME != G_ARRAY) { @@ -3683,7 +3862,7 @@ PP(pp_gprotoent) PUSHs(sv = sv_mortalcopy(&sv_no)); sv_setpv(sv, pent->p_name); PUSHs(sv = sv_mortalcopy(&sv_no)); - for (elem = pent->p_aliases; *elem; elem++) { + for (elem = pent->p_aliases; elem && *elem; elem++) { sv_catpv(sv, *elem); if (elem[1]) sv_catpvn(sv, " ", 1); @@ -3700,7 +3879,7 @@ PP(pp_gprotoent) PP(pp_gsbyname) { -#ifdef HAS_SOCKET +#ifdef HAS_GETSERVBYNAME return pp_gservent(ARGS); #else DIE(no_sock_func, "getservbyname"); @@ -3709,7 +3888,7 @@ PP(pp_gsbyname) PP(pp_gsbyport) { -#ifdef HAS_SOCKET +#ifdef HAS_GETSERVBYPORT return pp_gservent(ARGS); #else DIE(no_sock_func, "getservbyport"); @@ -3718,36 +3897,50 @@ PP(pp_gsbyport) PP(pp_gservent) { - dSP; -#ifdef HAS_SOCKET + djSP; +#if defined(HAS_GETSERVBYNAME) || defined(HAS_GETSERVBYPORT) || defined(HAS_GETSERVENT) I32 which = op->op_type; register char **elem; register SV *sv; - struct servent *getservbyname(); - struct servent *getservbynumber(); - struct servent *getservent(); +#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); + struct servent *PerlSock_getservent(void); +#endif struct servent *sent; if (which == OP_GSBYNAME) { +#ifdef HAS_GETSERVBYNAME char *proto = POPp; char *name = POPp; if (proto && !*proto) proto = Nullch; - sent = getservbyname(name, proto); + 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; #ifdef HAS_HTONS - port = htons(port); + port = PerlSock_htons(port); +#endif + sent = PerlSock_getservbyport(port, proto); +#else + DIE(no_sock_func, "getservbyport"); #endif - sent = getservbyport(port, proto); } else - sent = getservent(); +#ifdef HAS_GETSERVENT + sent = PerlSock_getservent(); +#else + DIE(no_sock_func, "getservent"); +#endif EXTEND(SP, 4); if (GIMME != G_ARRAY) { @@ -3755,7 +3948,7 @@ PP(pp_gservent) if (sent) { if (which == OP_GSBYNAME) { #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 @@ -3770,7 +3963,7 @@ PP(pp_gservent) PUSHs(sv = sv_mortalcopy(&sv_no)); sv_setpv(sv, sent->s_name); PUSHs(sv = sv_mortalcopy(&sv_no)); - for (elem = sent->s_aliases; *elem; elem++) { + for (elem = sent->s_aliases; elem && *elem; elem++) { sv_catpv(sv, *elem); if (elem[1]) sv_catpvn(sv, " ", 1); @@ -3793,8 +3986,8 @@ PP(pp_gservent) PP(pp_shostent) { - dSP; -#ifdef HAS_SOCKET + djSP; +#ifdef HAS_SETHOSTENT sethostent(TOPi); RETSETYES; #else @@ -3804,8 +3997,8 @@ PP(pp_shostent) PP(pp_snetent) { - dSP; -#ifdef HAS_SOCKET + djSP; +#ifdef HAS_SETNETENT setnetent(TOPi); RETSETYES; #else @@ -3815,8 +4008,8 @@ PP(pp_snetent) PP(pp_sprotoent) { - dSP; -#ifdef HAS_SOCKET + djSP; +#ifdef HAS_SETPROTOENT setprotoent(TOPi); RETSETYES; #else @@ -3826,8 +4019,8 @@ PP(pp_sprotoent) PP(pp_sservent) { - dSP; -#ifdef HAS_SOCKET + djSP; +#ifdef HAS_SETSERVENT setservent(TOPi); RETSETYES; #else @@ -3837,10 +4030,10 @@ PP(pp_sservent) PP(pp_ehostent) { - dSP; -#ifdef HAS_SOCKET - endhostent(); - EXTEND(sp,1); + djSP; +#ifdef HAS_ENDHOSTENT + PerlSock_endhostent(); + EXTEND(SP,1); RETPUSHYES; #else DIE(no_sock_func, "endhostent"); @@ -3849,10 +4042,10 @@ PP(pp_ehostent) PP(pp_enetent) { - dSP; -#ifdef HAS_SOCKET - endnetent(); - EXTEND(sp,1); + djSP; +#ifdef HAS_ENDNETENT + PerlSock_endnetent(); + EXTEND(SP,1); RETPUSHYES; #else DIE(no_sock_func, "endnetent"); @@ -3861,10 +4054,10 @@ PP(pp_enetent) PP(pp_eprotoent) { - dSP; -#ifdef HAS_SOCKET - endprotoent(); - EXTEND(sp,1); + djSP; +#ifdef HAS_ENDPROTOENT + PerlSock_endprotoent(); + EXTEND(SP,1); RETPUSHYES; #else DIE(no_sock_func, "endprotoent"); @@ -3873,10 +4066,10 @@ PP(pp_eprotoent) PP(pp_eservent) { - dSP; -#ifdef HAS_SOCKET - endservent(); - EXTEND(sp,1); + djSP; +#ifdef HAS_ENDSERVENT + PerlSock_endservent(); + EXTEND(SP,1); RETPUSHYES; #else DIE(no_sock_func, "endservent"); @@ -3903,7 +4096,7 @@ PP(pp_gpwuid) PP(pp_gpwent) { - dSP; + djSP; #ifdef HAS_PASSWD I32 which = op->op_type; register SV *sv; @@ -3959,6 +4152,9 @@ PP(pp_gpwent) #endif PUSHs(sv = sv_mortalcopy(&sv_no)); sv_setpv(sv, pwent->pw_gecos); +#ifndef INCOMPLETE_TAINTS + SvTAINTED_on(sv); +#endif PUSHs(sv = sv_mortalcopy(&sv_no)); sv_setpv(sv, pwent->pw_dir); PUSHs(sv = sv_mortalcopy(&sv_no)); @@ -3976,8 +4172,8 @@ PP(pp_gpwent) PP(pp_spwent) { - dSP; -#ifdef HAS_PASSWD + djSP; +#if defined(HAS_PASSWD) && !defined(CYGWIN32) setpwent(); RETPUSHYES; #else @@ -3987,7 +4183,7 @@ PP(pp_spwent) PP(pp_epwent) { - dSP; + djSP; #ifdef HAS_PASSWD endpwent(); RETPUSHYES; @@ -4016,7 +4212,7 @@ PP(pp_ggrgid) PP(pp_ggrent) { - dSP; + djSP; #ifdef HAS_GROUP I32 which = op->op_type; register char **elem; @@ -4050,7 +4246,7 @@ PP(pp_ggrent) PUSHs(sv = sv_mortalcopy(&sv_no)); sv_setiv(sv, (IV)grent->gr_gid); PUSHs(sv = sv_mortalcopy(&sv_no)); - for (elem = grent->gr_mem; *elem; elem++) { + for (elem = grent->gr_mem; elem && *elem; elem++) { sv_catpv(sv, *elem); if (elem[1]) sv_catpvn(sv, " ", 1); @@ -4065,7 +4261,7 @@ PP(pp_ggrent) PP(pp_sgrent) { - dSP; + djSP; #ifdef HAS_GROUP setgrent(); RETPUSHYES; @@ -4076,7 +4272,7 @@ PP(pp_sgrent) PP(pp_egrent) { - dSP; + djSP; #ifdef HAS_GROUP endgrent(); RETPUSHYES; @@ -4087,7 +4283,7 @@ PP(pp_egrent) PP(pp_getlogin) { - dSP; dTARGET; + djSP; dTARGET; #ifdef HAS_GETLOGIN char *tmps; EXTEND(SP, 1); @@ -4104,8 +4300,8 @@ PP(pp_getlogin) PP(pp_syscall) { -#ifdef HAS_SYSCALL - dSP; dMARK; dORIGMARK; dTARGET; +#ifdef HAS_SYSCALL + djSP; dMARK; dORIGMARK; dTARGET; register I32 items = SP - MARK; unsigned long a[20]; register I32 i = 0; @@ -4206,9 +4402,7 @@ PP(pp_syscall) */ static int -fcntl_emulate_flock(fd, operation) -int fd; -int operation; +fcntl_emulate_flock(int fd, int operation) { struct flock flock; @@ -4270,6 +4464,17 @@ int fd; int operation; { int i; + int save_errno; + Off_t pos; + + /* flock locks entire file so for lockf we need to do the same */ + save_errno = errno; + pos = PerlLIO_lseek(fd, (Off_t)0, SEEK_CUR); /* get pos to restore later */ + if (pos > 0) /* is seekable and needs to be repositioned */ + if (PerlLIO_lseek(fd, (Off_t)0, SEEK_SET) < 0) + pos = -1; /* seek failed, so don't seek back afterwards */ + errno = save_errno; + switch (operation) { /* LOCK_SH - get a shared lock */ @@ -4301,7 +4506,12 @@ int operation; errno = EINVAL; break; } + + if (pos > 0) /* need to restore position of the handle */ + PerlLIO_lseek(fd, pos, SEEK_SET); /* ignore error here */ + return (i); } #endif /* LOCKF_EMULATE_FLOCK */ +