X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pp_sys.c;h=3429c45d563640507df3f775fa3e685595ef48c5;hb=706de38c2aa2b981f7071fda099501bf2cc8caeb;hp=ea34bae31ea5ee1d3f8d41f461e827d02a7303ac;hpb=894356b32151f778d4d2915c6db38e5d049b115a;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pp_sys.c b/pp_sys.c index ea34bae..3429c45 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -1,6 +1,6 @@ /* pp_sys.c * - * Copyright (c) 1991-1999, Larry Wall + * Copyright (c) 1991-2000, Larry Wall * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. @@ -77,7 +77,7 @@ extern "C" int syscall(unsigned long,...); compiling multithreaded and singlethreaded ($ccflags et al). HOST_NOT_FOUND is typically defined in . */ -#if defined(HOST_NOT_FOUND) && !defined(h_errno) +#if defined(HOST_NOT_FOUND) && !defined(h_errno) && !defined(__CYGWIN__) extern int h_errno; #endif @@ -112,27 +112,12 @@ extern int h_errno; # include # endif #endif -#ifdef I_FCNTL -#include -#endif -#ifdef I_SYS_FILE -#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 - #ifdef HAS_CHSIZE # ifdef my_chsize /* Probably #defined to Perl_my_chsize in embed.h */ # undef my_chsize @@ -374,6 +359,9 @@ PP(pp_glob) ENTER; #ifndef VMS + /* If we're not using an external glob, just let readdir() tainting + * do its thing. Otherwise, engage paranoia mode. */ +#if defined(PERL_EXTERNAL_GLOB) if (PL_tainting) { /* * The external globbing program may use things we can't control, @@ -382,6 +370,7 @@ PP(pp_glob) TAINT; taint_proper(PL_no_security, "glob"); } +#endif /* PERL_EXTERNAL_GLOB */ #endif /* !VMS */ SAVESPTR(PL_last_in_gv); /* We don't want this to be permanent. */ @@ -943,7 +932,7 @@ PP(pp_sselect) /* If SELECT_MIN_BITS is greater than one we most probably will want * to align the sizes with SELECT_MIN_BITS/8 because for example * in many little-endian (Intel, Alpha) systems (Linux, OS/2, Digital - * UNIX, Solaris, NeXT, Rhapsody) the smallest quantum select() operates + * UNIX, Solaris, NeXT, Darwin) the smallest quantum select() operates * on (sets/tests/clears bits) is 32 bits. */ growsize = maxlen + (SELECT_MIN_BITS/8 - (maxlen % (SELECT_MIN_BITS/8))); # else @@ -1091,7 +1080,7 @@ PP(pp_getc) GV *gv; MAGIC *mg; - if (MAXARG <= 0) + if (MAXARG == 0) gv = PL_stdingv; else gv = (GV*)POPs; @@ -1701,7 +1690,7 @@ PP(pp_eof) GV *gv; MAGIC *mg; - if (MAXARG <= 0) { + if (MAXARG == 0) { if (PL_op->op_flags & OPf_SPECIAL) { /* eof() */ IO *io; gv = PL_last_in_gv = PL_argvgv; @@ -1745,7 +1734,7 @@ PP(pp_tell) GV *gv; MAGIC *mg; - if (MAXARG <= 0) + if (MAXARG == 0) gv = PL_last_in_gv; else gv = PL_last_in_gv = (GV*)POPs; @@ -1791,7 +1780,11 @@ PP(pp_sysseek) if (gv && (mg = SvTIED_mg((SV*)gv, 'q'))) { PUSHMARK(SP); XPUSHs(SvTIED_obj((SV*)gv, mg)); +#if LSEEKSIZE > IVSIZE + XPUSHs(sv_2mortal(newSVnv((NV) offset))); +#else XPUSHs(sv_2mortal(newSViv((IV) offset))); +#endif XPUSHs(sv_2mortal(newSViv((IV) whence))); PUTBACK; ENTER; @@ -1835,13 +1828,17 @@ PP(pp_truncate) tmpgv = gv_fetchpv(POPpx, FALSE, SVt_PVIO); do_ftruncate: TAINT_PROPER("truncate"); - if (!GvIO(tmpgv) || !IoIFP(GvIOp(tmpgv)) || + if (!GvIO(tmpgv) || !IoIFP(GvIOp(tmpgv))) + result = 0; + else { + PerlIO_flush(IoIFP(GvIOp(tmpgv))); #ifdef HAS_TRUNCATE - ftruncate(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), len) < 0) + if (ftruncate(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), len) < 0) #else - my_chsize(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), len) < 0) + if (my_chsize(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), len) < 0) #endif - result = 0; + result = 0; + } } else { SV *sv = POPs; @@ -1972,7 +1969,7 @@ PP(pp_flock) #ifdef FLOCK argtype = POPi; - if (MAXARG <= 0) + if (MAXARG == 0) gv = PL_last_in_gv; else gv = (GV*)POPs; @@ -2034,6 +2031,9 @@ PP(pp_socket) if (!IoIFP(io) && !IoOFP(io)) PerlLIO_close(fd); RETPUSHUNDEF; } +#if defined(HAS_FCNTL) && defined(F_SETFD) + fcntl(fd, F_SETFD, fd > PL_maxsysfd); /* ensure close-on-exec */ +#endif RETPUSHYES; #else @@ -2084,6 +2084,10 @@ PP(pp_sockpair) if (!IoIFP(io2) && !IoOFP(io2)) PerlLIO_close(fd[1]); RETPUSHUNDEF; } +#if defined(HAS_FCNTL) && defined(F_SETFD) + fcntl(fd[0],F_SETFD,fd[0] > PL_maxsysfd); /* ensure close-on-exec */ + fcntl(fd[1],F_SETFD,fd[1] > PL_maxsysfd); /* ensure close-on-exec */ +#endif RETPUSHYES; #else @@ -2246,6 +2250,9 @@ PP(pp_accept) if (!IoIFP(nstio) && !IoOFP(nstio)) PerlLIO_close(fd); goto badexit; } +#if defined(HAS_FCNTL) && defined(F_SETFD) + fcntl(fd, F_SETFD, fd > PL_maxsysfd); /* ensure close-on-exec */ +#endif PUSHp((char *)&saddr, len); RETURN; @@ -3364,12 +3371,19 @@ S_dooneliner(pTHX_ char *cmd, char *filename) PP(pp_mkdir) { djSP; dTARGET; - int mode = POPi; + int mode; #ifndef HAS_MKDIR int oldumask; #endif STRLEN n_a; - char *tmps = SvPV(TOPs, n_a); + char *tmps; + + if (MAXARG > 1) + mode = POPi; + else + mode = 0777; + + tmps = SvPV(TOPs, n_a); TAINT_PROPER("mkdir"); #ifdef HAS_MKDIR @@ -3452,7 +3466,8 @@ PP(pp_readdir) sv = newSVpv(dp->d_name, 0); #endif #ifndef INCOMPLETE_TAINTS - SvTAINTED_on(sv); + if (!(IoFLAGS(io) & IOf_UNTAINT)) + SvTAINTED_on(sv); #endif XPUSHs(sv_2mortal(sv)); } @@ -3466,7 +3481,8 @@ PP(pp_readdir) sv = newSVpv(dp->d_name, 0); #endif #ifndef INCOMPLETE_TAINTS - SvTAINTED_on(sv); + if (!(IoFLAGS(io) & IOf_UNTAINT)) + SvTAINTED_on(sv); #endif XPUSHs(sv_2mortal(sv)); } @@ -4704,7 +4720,7 @@ PP(pp_gpwuid) PP(pp_gpwent) { djSP; -#if defined(HAS_PASSWD) && defined(HAS_GETPWENT) +#ifdef HAS_PASSWD I32 which = PL_op->op_type; register SV *sv; struct passwd *pwent; @@ -4718,7 +4734,11 @@ PP(pp_gpwent) else if (which == OP_GPWUID) pwent = getpwuid(POPi); else +#ifdef HAS_GETPWENT pwent = (struct passwd *)getpwent(); +#else + DIE(aTHX_ PL_no_func, "getpwent"); +#endif #ifdef HAS_GETSPNAM if (which == OP_GPWNAM) { @@ -4870,7 +4890,7 @@ PP(pp_ggrgid) PP(pp_ggrent) { djSP; -#if defined(HAS_GROUP) && defined(HAS_GETGRENT) +#ifdef HAS_GROUP I32 which = PL_op->op_type; register char **elem; register SV *sv; @@ -4882,7 +4902,11 @@ PP(pp_ggrent) else if (which == OP_GGRGID) grent = (struct group *)getgrgid(POPi); else +#ifdef HAS_GETGRENT grent = (struct group *)getgrent(); +#else + DIE(aTHX_ PL_no_func, "getgrent"); +#endif EXTEND(SP, 4); if (GIMME != G_ARRAY) {