fix problem pointer casts
[p5sagit/p5-mst-13.2.git] / pp_sys.c
index 2a0ec38..b2495a0 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -411,7 +411,7 @@ PP(pp_indread)
 
 PP(pp_rcatline)
 {
-    PL_last_in_gv = cGVOP->op_gv;
+    PL_last_in_gv = cGVOP;
     return do_readline();
 }
 
@@ -475,8 +475,8 @@ PP(pp_die)
                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));
+                   SV *file = sv_2mortal(newSVpv(CopFILE(PL_curcop),0));
+                   SV *line = sv_2mortal(newSViv(CopLINE(PL_curcop)));
                    EXTEND(SP, 3);
                    PUSHMARK(SP);
                    PUSHs(error);
@@ -532,22 +532,6 @@ PP(pp_open)
     if (GvIOp(gv))
        IoFLAGS(GvIOp(gv)) &= ~IOf_UNTAINT;
 
-#if 0 /* no undef means tmpfile() yet */
-    if (sv == &PL_sv_undef) {
-#ifdef PerlIO
-       PerlIO *fp = PerlIO_tmpfile();
-#else
-       PerlIO *fp = tmpfile();
-#endif                   
-       if (fp != Nullfp && do_open(gv, "+>&", 3, FALSE, 0, 0, fp)) 
-           PUSHi( (I32)PL_forkprocess );
-       else
-           RETPUSHUNDEF;
-       RETURN;
-    }   
-#endif /* no undef means tmpfile() yet */
-
-
     if (mg = SvTIED_mg((SV*)gv, 'q')) {
        PUSHMARK(SP);
        XPUSHs(SvTIED_obj((SV*)gv, mg));
@@ -825,17 +809,10 @@ PP(pp_untie)
     if (ckWARN(WARN_UNTIE)) {
         MAGIC * mg ;
         if (mg = SvTIED_mg(sv, how)) {
-#ifdef IV_IS_QUAD
             if (mg && SvREFCNT(SvRV(mg->mg_obj)) > 1)  
                Perl_warner(aTHX_ WARN_UNTIE,
-                   "untie attempted while %" PERL_PRIu64 " inner references still exist",
+                   "untie attempted while %"UVuf" inner references still exist",
                    (UV)SvREFCNT(SvRV(mg->mg_obj)) - 1 ) ;
-#else
-            if (mg && SvREFCNT(SvRV(mg->mg_obj)) > 1)  
-               Perl_warner(aTHX_ WARN_UNTIE,
-                   "untie attempted while %lu inner references still exist",
-                   (unsigned long)SvREFCNT(SvRV(mg->mg_obj)) - 1 ) ;
-#endif
         }
     }
  
@@ -1615,10 +1592,10 @@ PP(pp_send)
     djSP; dMARK; dORIGMARK; dTARGET;
     GV *gv;
     IO *io;
-    int offset;
+    Off_t offset;
     SV *bufsv;
     char *buffer;
-    int length;
+    Off_t length;
     STRLEN blen;
     MAGIC *mg;
 
@@ -1641,7 +1618,11 @@ PP(pp_send)
        goto say_undef;
     bufsv = *++MARK;
     buffer = SvPV(bufsv, blen);
+#if Off_t_SIZE > IVSIZE
+    length = SvNVx(*++MARK);
+#else
     length = SvIVx(*++MARK);
+#endif
     if (length < 0)
        DIE(aTHX_ "Negative length");
     SETERRNO(0,0);
@@ -1657,7 +1638,11 @@ PP(pp_send)
     }
     else if (PL_op->op_type == OP_SYSWRITE) {
        if (MARK < SP) {
+#if Off_t_SIZE > IVSIZE
+           offset = SvNVx(*++MARK);
+#else
            offset = SvIVx(*++MARK);
+#endif
            if (offset < 0) {
                if (-offset > blen)
                    DIE(aTHX_ "Offset outside string");
@@ -1760,7 +1745,11 @@ PP(pp_tell)
        RETURN;
     }
 
+#if LSEEKSIZE > IVSIZE
+    PUSHn( do_tell(gv) );
+#else
     PUSHi( do_tell(gv) );
+#endif
     RETURN;
 }
 
@@ -1774,7 +1763,11 @@ PP(pp_sysseek)
     djSP;
     GV *gv;
     int whence = POPi;
+#if LSEEKSIZE > IVSIZE
+    Off_t offset = (Off_t)SvNVx(POPs);
+#else
     Off_t offset = (Off_t)SvIVx(POPs);
+#endif
     MAGIC *mg;
 
     gv = PL_last_in_gv = (GV*)POPs;
@@ -1796,9 +1789,18 @@ PP(pp_sysseek)
        PUSHs(boolSV(do_seek(gv, offset, whence)));
     else {
        Off_t n = do_sysseek(gv, offset, whence);
-       PUSHs((n < 0) ? &PL_sv_undef
-             : sv_2mortal(n ? newSViv((IV)n)
-                          : newSVpvn(zero_but_true, ZBTLEN)));
+        if (n < 0)
+            PUSHs(&PL_sv_undef);
+        else {
+            SV* sv = n ?
+#if LSEEKSIZE > IVSIZE
+                newSVnv((NV)n)
+#else
+                newSViv((IV)n)
+#endif
+                : newSVpvn(zero_but_true, ZBTLEN);
+            PUSHs(sv_2mortal(sv));
+        }
     }
     RETURN;
 }
@@ -2435,7 +2437,7 @@ PP(pp_stat)
     STRLEN n_a;
 
     if (PL_op->op_flags & OPf_REF) {
-       tmpgv = cGVOP->op_gv;
+       tmpgv = cGVOP;
       do_fstat:
        if (tmpgv != PL_defgv) {
            PL_laststype = OP_STAT;
@@ -2486,14 +2488,26 @@ PP(pp_stat)
        PUSHs(sv_2mortal(newSViv(PL_statcache.st_ino)));
        PUSHs(sv_2mortal(newSViv(PL_statcache.st_mode)));
        PUSHs(sv_2mortal(newSViv(PL_statcache.st_nlink)));
+#if Uid_t_size > IVSIZE
+       PUSHs(sv_2mortal(newSVnv(PL_statcache.st_uid)));
+#else
        PUSHs(sv_2mortal(newSViv(PL_statcache.st_uid)));
+#endif
+#if Gid_t_size > IVSIZE 
+       PUSHs(sv_2mortal(newSVnv(PL_statcache.st_gid)));
+#else
        PUSHs(sv_2mortal(newSViv(PL_statcache.st_gid)));
+#endif
 #ifdef USE_STAT_RDEV
        PUSHs(sv_2mortal(newSViv(PL_statcache.st_rdev)));
 #else
        PUSHs(sv_2mortal(newSVpvn("", 0)));
 #endif
+#if Off_t_size > IVSIZE
+       PUSHs(sv_2mortal(newSVnv(PL_statcache.st_size)));
+#else
        PUSHs(sv_2mortal(newSViv(PL_statcache.st_size)));
+#endif
 #ifdef BIG_TIME
        PUSHs(sv_2mortal(newSVnv(PL_statcache.st_atime)));
        PUSHs(sv_2mortal(newSVnv(PL_statcache.st_mtime)));
@@ -2696,7 +2710,8 @@ PP(pp_ftrowned)
     djSP;
     if (result < 0)
        RETPUSHUNDEF;
-    if (PL_statcache.st_uid == (PL_op->op_type == OP_FTEOWNED ? PL_euid : PL_uid) )
+    if (PL_statcache.st_uid == (PL_op->op_type == OP_FTEOWNED ?
+                               PL_euid : PL_uid) )
        RETPUSHYES;
     RETPUSHNO;
 }
@@ -2707,7 +2722,7 @@ PP(pp_ftzero)
     djSP;
     if (result < 0)
        RETPUSHUNDEF;
-    if (!PL_statcache.st_size)
+    if (PL_statcache.st_size == 0)
        RETPUSHYES;
     RETPUSHNO;
 }
@@ -2718,7 +2733,11 @@ PP(pp_ftsize)
     djSP; dTARGET;
     if (result < 0)
        RETPUSHUNDEF;
+#if Off_t_size > IVSIZE
+    PUSHn(PL_statcache.st_size);
+#else
     PUSHi(PL_statcache.st_size);
+#endif
     RETURN;
 }
 
@@ -2880,7 +2899,7 @@ PP(pp_fttty)
     STRLEN n_a;
 
     if (PL_op->op_flags & OPf_REF)
-       gv = cGVOP->op_gv;
+       gv = cGVOP;
     else if (isGV(TOPs))
        gv = (GV*)POPs;
     else if (SvROK(TOPs) && isGV(SvRV(TOPs)))
@@ -2919,9 +2938,10 @@ PP(pp_fttext)
     register SV *sv;
     GV *gv;
     STRLEN n_a;
+    PerlIO *fp;
 
     if (PL_op->op_flags & OPf_REF)
-       gv = cGVOP->op_gv;
+       gv = cGVOP;
     else if (isGV(TOPs))
        gv = (GV*)POPs;
     else if (SvROK(TOPs) && isGV(SvRV(TOPs)))
@@ -2972,7 +2992,7 @@ PP(pp_fttext)
        else {
            if (ckWARN(WARN_UNOPENED))
                Perl_warner(aTHX_ WARN_UNOPENED, "Test on unopened file <%s>",
-                 GvENAME(cGVOP->op_gv));
+                           GvENAME(cGVOP));
            SETERRNO(EBADF,RMS$_IFI);
            RETPUSHUNDEF;
        }
@@ -2983,21 +3003,19 @@ PP(pp_fttext)
        PL_statgv = Nullgv;
        PL_laststatval = -1;
        sv_setpv(PL_statname, SvPV(sv, n_a));
-#ifdef HAS_OPEN3
-       i = PerlLIO_open3(SvPV(sv, n_a), O_RDONLY, 0);
-#else
-       i = PerlLIO_open(SvPV(sv, n_a), 0);
-#endif
-       if (i < 0) {
+       if (!(fp = PerlIO_open(SvPVX(PL_statname), "r"))) {
            if (ckWARN(WARN_NEWLINE) && strchr(SvPV(sv, n_a), '\n'))
                Perl_warner(aTHX_ WARN_NEWLINE, PL_warn_nl, "open");
            RETPUSHUNDEF;
        }
-       PL_laststatval = PerlLIO_fstat(i, &PL_statcache);
-       if (PL_laststatval < 0)
+       PL_laststatval = PerlLIO_fstat(PerlIO_fileno(fp), &PL_statcache);
+       if (PL_laststatval < 0) {
+           (void)PerlIO_close(fp);
            RETPUSHUNDEF;
-       len = PerlLIO_read(i, tbuf, 512);
-       (void)PerlLIO_close(i);
+       }
+       do_binmode(fp, '<', TRUE);
+       len = PerlIO_read(fp, tbuf, sizeof(tbuf));
+       (void)PerlIO_close(fp);
        if (len <= 0) {
            if (S_ISDIR(PL_statcache.st_mode) && PL_op->op_type == OP_FTTEXT)
                RETPUSHNO;              /* special case NFS directories */
@@ -3009,6 +3027,12 @@ PP(pp_fttext)
     /* now scan s to look for textiness */
     /*   XXX ASCII dependent code */
 
+#if defined(DOSISH) || defined(USEMYBINMODE)
+    /* ignore trailing ^Z on short files */
+    if (len && len < sizeof(tbuf) && tbuf[len-1] == 26)
+       --len;
+#endif
+
     for (i = 0; i < len; i++, s++) {
        if (!*s) {                      /* null never allowed in text */
            odd += len;
@@ -3018,8 +3042,12 @@ PP(pp_fttext)
         else if (!(isPRINT(*s) || isSPACE(*s))) 
             odd++;
 #else
-       else if (*s & 128)
-           odd++;
+       else if (*s & 128) {
+#ifdef USE_LOCALE
+           if (!(PL_op->op_private & OPpLOCALE) || !isALPHA_LC(*s))
+#endif
+               odd++;
+       }
        else if (*s < 32 &&
          *s != '\n' && *s != '\r' && *s != '\b' &&
          *s != '\t' && *s != '\f' && *s != 27)
@@ -3172,7 +3200,7 @@ PP(pp_link)
     char *tmps2 = POPpx;
     char *tmps = SvPV(TOPs, n_a);
     TAINT_PROPER("link");
-    SETi( link(tmps, tmps2) >= 0 );
+    SETi( PerlLIO_link(tmps, tmps2) >= 0 );
 #else
     DIE(aTHX_ PL_no_func, "Unsupported function link");
 #endif
@@ -3560,7 +3588,7 @@ PP(pp_fork)
 
 PP(pp_wait)
 {
-#if !defined(DOSISH) || defined(OS2) || defined(WIN32)
+#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL) 
     djSP; dTARGET;
     Pid_t childpid;
     int argflags;
@@ -3576,7 +3604,7 @@ PP(pp_wait)
 
 PP(pp_waitpid)
 {
-#if !defined(DOSISH) || defined(OS2) || defined(WIN32)
+#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL) 
     djSP; dTARGET;
     Pid_t childpid;
     int optype;
@@ -3657,7 +3685,7 @@ PP(pp_system)
            PerlLIO_close(pp[0]);
            if (n) {                    /* Error */
                if (n != sizeof(int))
-                   Perl_croak(aTHX_ "panic: kid popen errno read");
+                   DIE(aTHX_ "panic: kid popen errno read");
                errno = errkid;         /* Propagate errno from kid */
                STATUS_CURRENT = -1;
            }
@@ -3815,7 +3843,7 @@ PP(pp_setpgrp)
     SETi( BSD_SETPGRP(pid, pgrp) >= 0 );
 #else
     if ((pgrp != 0 && pgrp != getpid()) || (pid != 0 && pid != getpid()))
-       DIE(aTHX_ "POSIX setpgrp can't take an argument");
+       DIE(aTHX_ "setpgrp can't take arguments");
     SETi( setpgrp() >= 0 );
 #endif /* USE_BSDPGRP */
     RETURN;