This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Minor perlreapi.pod cleanup
[perl5.git] / doio.c
diff --git a/doio.c b/doio.c
index 4b84bdb..7269c28 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -1196,32 +1196,24 @@ bool
 Perl_do_print(pTHX_ register SV *sv, PerlIO *fp)
 {
     dVAR;
-    register const char *tmps;
-    STRLEN len;
-    U8 *tmpbuf = NULL;
-    bool happy = TRUE;
-
     /* assuming fp is checked earlier */
     if (!sv)
        return TRUE;
-    switch (SvTYPE(sv)) {
-    case SVt_NULL:
-       if (ckWARN(WARN_UNINITIALIZED))
-           report_uninit(sv);
-       return TRUE;
-    case SVt_IV:
-       if (SvIOK(sv)) {
-           assert(!SvGMAGICAL(sv));
-           if (SvIsUV(sv))
-               PerlIO_printf(fp, "%"UVuf, (UV)SvUVX(sv));
-           else
-               PerlIO_printf(fp, "%"IVdf, (IV)SvIVX(sv));
-           return !PerlIO_error(fp);
-       }
-       /* FALL THROUGH */
-    default:
+    if (SvTYPE(sv) == SVt_IV && SvIOK(sv)) {
+       assert(!SvGMAGICAL(sv));
+       if (SvIsUV(sv))
+           PerlIO_printf(fp, "%"UVuf, (UV)SvUVX(sv));
+       else
+           PerlIO_printf(fp, "%"IVdf, (IV)SvIVX(sv));
+       return !PerlIO_error(fp);
+    }
+    else {
+       STRLEN len;
        /* Do this first to trigger any overloading.  */
-       tmps = SvPV_const(sv, len);
+       const char *tmps = SvPV_const(sv, len);
+       U8 *tmpbuf = NULL;
+       bool happy = TRUE;
+
        if (PerlIO_isutf8(fp)) {
            if (!SvUTF8(sv)) {
                /* We don't modify the original scalar.  */
@@ -1246,18 +1238,17 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp)
                }
            }
        }
-       break;
+       /* To detect whether the process is about to overstep its
+        * filesize limit we would need getrlimit().  We could then
+        * also transparently raise the limit with setrlimit() --
+        * but only until the system hard limit/the filesystem limit,
+        * at which we would get EPERM.  Note that when using buffered
+        * io the write failure can be delayed until the flush/close. --jhi */
+       if (len && (PerlIO_write(fp,tmps,len) == 0))
+           happy = FALSE;
+       Safefree(tmpbuf);
+       return happy ? !PerlIO_error(fp) : FALSE;
     }
-    /* To detect whether the process is about to overstep its
-     * filesize limit we would need getrlimit().  We could then
-     * also transparently raise the limit with setrlimit() --
-     * but only until the system hard limit/the filesystem limit,
-     * at which we would get EPERM.  Note that when using buffered
-     * io the write failure can be delayed until the flush/close. --jhi */
-    if (len && (PerlIO_write(fp,tmps,len) == 0))
-       happy = FALSE;
-    Safefree(tmpbuf);
-    return happy ? !PerlIO_error(fp) : FALSE;
 }
 
 I32
@@ -1283,17 +1274,7 @@ Perl_my_stat(pTHX)
            if (IoIFP(io)) {
                return (PL_laststatval = PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache));
             } else if (IoDIRP(io)) {
-#ifdef HAS_DIRFD
-                return (PL_laststatval = PerlLIO_fstat(dirfd(IoDIRP(io)), &PL_statcache));
-#else
-                Perl_die(aTHX_ PL_no_func, "dirfd");
-               /* NOT REACHED */
-               return 0;
-               /* Can't use NORETURN_FUNCTION_END because Perl_die is not
-                *     __attribute__noreturn__
-                * Can't use DIE because that does not return an integer
-                */
-#endif
+                return (PL_laststatval = PerlLIO_fstat(my_dirfd(IoDIRP(io)), &PL_statcache));
             } else {
                 if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
                     report_evil_fh(gv, io, PL_op->op_type);
@@ -1618,7 +1599,7 @@ Perl_apply(pTHX_ I32 type, register SV **mark, register SV **sp)
     case OP_CHMOD:
        APPLY_TAINT_PROPER();
        if (++mark <= sp) {
-           val = SvIVx(*mark);
+           val = SvIV(*mark);
            APPLY_TAINT_PROPER();
            tot = sp - mark;
            while (++mark <= sp) {
@@ -1712,7 +1693,7 @@ nothing in the core.
                Perl_croak(aTHX_ "Unrecognized signal name \"%s\"",s);
        }
        else
-           val = SvIVx(*mark);
+           val = SvIV(*mark);
        APPLY_TAINT_PROPER();
        tot = sp - mark;
 #ifdef VMS
@@ -1725,7 +1706,7 @@ nothing in the core.
             * CRTL's emulation of Unix-style signals and kill()
             */
            while (++mark <= sp) {
-               I32 proc = SvIVx(*mark);
+               I32 proc = SvIV(*mark);
                register unsigned long int __vmssts;
                APPLY_TAINT_PROPER();
                if (!((__vmssts = sys$delprc(&proc,0)) & 1)) {
@@ -1749,7 +1730,7 @@ nothing in the core.
        if (val < 0) {
            val = -val;
            while (++mark <= sp) {
-               const I32 proc = SvIVx(*mark);
+               const I32 proc = SvIV(*mark);
                APPLY_TAINT_PROPER();
 #ifdef HAS_KILLPG
                if (PerlProc_killpg(proc,val))  /* BSD */
@@ -1761,7 +1742,7 @@ nothing in the core.
        }
        else {
            while (++mark <= sp) {
-               const I32 proc = SvIVx(*mark);
+               const I32 proc = SvIV(*mark);
                APPLY_TAINT_PROPER();
                if (PerlProc_kill(proc, val))
                    tot--;
@@ -1819,16 +1800,16 @@ nothing in the core.
            else {
                 Zero(&utbuf, sizeof utbuf, char);
 #ifdef HAS_FUTIMES
-               utbuf[0].tv_sec = (long)SvIVx(accessed);  /* time accessed */
+               utbuf[0].tv_sec = (long)SvIV(accessed);  /* time accessed */
                utbuf[0].tv_usec = 0;
-               utbuf[1].tv_sec = (long)SvIVx(modified);  /* time modified */
+               utbuf[1].tv_sec = (long)SvIV(modified);  /* time modified */
                utbuf[1].tv_usec = 0;
 #elif defined(BIG_TIME)
-                utbuf.actime = (Time_t)SvNVx(accessed);  /* time accessed */
-                utbuf.modtime = (Time_t)SvNVx(modified); /* time modified */
+                utbuf.actime = (Time_t)SvNV(accessed);  /* time accessed */
+                utbuf.modtime = (Time_t)SvNV(modified); /* time modified */
 #else
-                utbuf.actime = (Time_t)SvIVx(accessed);  /* time accessed */
-                utbuf.modtime = (Time_t)SvIVx(modified); /* time modified */
+                utbuf.actime = (Time_t)SvIV(accessed);  /* time accessed */
+                utbuf.modtime = (Time_t)SvIV(modified); /* time modified */
 #endif
             }
            APPLY_TAINT_PROPER();
@@ -1841,7 +1822,8 @@ nothing in the core.
                    if (GvIO(gv) && IoIFP(GvIOp(gv))) {
 #ifdef HAS_FUTIMES
                        APPLY_TAINT_PROPER();
-                       if (futimes(PerlIO_fileno(IoIFP(GvIOn(gv))), utbufp))
+                       if (futimes(PerlIO_fileno(IoIFP(GvIOn(gv))),
+                            (struct timeval *) utbufp))
                            tot--;
 #else
                        Perl_die(aTHX_ PL_no_func, "futimes");
@@ -1859,7 +1841,7 @@ nothing in the core.
                    const char * const name = SvPV_nolen_const(*mark);
                    APPLY_TAINT_PROPER();
 #ifdef HAS_FUTIMES
-                   if (utimes(name, utbufp))
+                   if (utimes(name, (struct timeval *)utbufp))
 #else
                    if (PerlLIO_utime(name, utbufp))
 #endif