do subname() is deprecated, so update this hunk of test dating from perl 1.
[p5sagit/p5-mst-13.2.git] / pp_sys.c
index b42cced..4c00651 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
 #include "EXTERN.h"
 #define PERL_IN_PP_SYS_C
 #include "perl.h"
-#if !defined(PERL_MICRO) && defined(Quad_t)
-#  include "time64.h"
-#  include "time64.c"
-#endif
+#include "time64.h"
+#include "time64.c"
 
 #ifdef I_SHADOW
 /* Shadow password support for solaris - pdo@cs.umd.edu
@@ -244,7 +242,6 @@ S_emulate_eaccess(pTHX_ const char* path, Mode_t mode)
     const Gid_t egid = getegid();
     int res;
 
-    LOCK_CRED_MUTEX;
 #if !defined(HAS_SETREUID) && !defined(HAS_SETRESUID)
     Perl_croak(aTHX_ "switching effective uid is not implemented");
 #else
@@ -290,7 +287,6 @@ S_emulate_eaccess(pTHX_ const char* path, Mode_t mode)
 #endif
 #endif
        Perl_croak(aTHX_ "leaving effective gid failed");
-    UNLOCK_CRED_MUTEX;
 
     return res;
 }
@@ -525,9 +521,9 @@ PP(pp_open)
        MAGIC *mg;
        IoFLAGS(GvIOp(gv)) &= ~IOf_UNTAINT;
 
-       if (IoDIRP(io) && ckWARN2(WARN_IO, WARN_DEPRECATED))
-           Perl_warner(aTHX_ packWARN2(WARN_IO, WARN_DEPRECATED),
-                   "Opening dirhandle %s also as a file", GvENAME(gv));
+       if (IoDIRP(io))
+           Perl_ck_warner(aTHX_ packWARN2(WARN_IO, WARN_DEPRECATED),
+                          "Opening dirhandle %s also as a file", GvENAME(gv));
 
        mg = SvTIED_mg((const SV *)io, PERL_MAGIC_tiedscalar);
        if (mg) {
@@ -804,11 +800,6 @@ PP(pp_tie)
            break;
        case SVt_PVGV:
            if (isGV_with_GP(varsv)) {
-#ifdef GV_UNIQUE_CHECK
-               if (GvUNIQUE((const GV *)varsv)) {
-                   Perl_croak(aTHX_ "Attempt to tie unique GV");
-               }
-#endif
                methname = "TIEHANDLE";
                how = PERL_MAGIC_tiedscalar;
                /* For tied filehandles, we apply tiedscalar magic to the IO
@@ -901,10 +892,10 @@ PP(pp_untie)
               LEAVE;
               SPAGAIN;
             }
-           else if (mg && SvREFCNT(obj) > 1 && ckWARN(WARN_UNTIE)) {
-                 Perl_warner(aTHX_ packWARN(WARN_UNTIE),
-                     "untie attempted while %"UVuf" inner references still exist",
-                      (UV)SvREFCNT(obj) - 1 ) ;
+           else if (mg && SvREFCNT(obj) > 1) {
+               Perl_ck_warner(aTHX_ packWARN(WARN_UNTIE),
+                              "untie attempted while %"UVuf" inner references still exist",
+                              (UV)SvREFCNT(obj) - 1 ) ;
            }
         }
     }
@@ -1027,8 +1018,7 @@ PP(pp_sselect)
                DIE(aTHX_ "%s", PL_no_modify);
        }
        if (!SvPOK(sv)) {
-           if (ckWARN(WARN_MISC))
-                Perl_warner(aTHX_ packWARN(WARN_MISC), "Non-string passed as bitmask");
+           Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "Non-string passed as bitmask");
            SvPV_force_nolen(sv);       /* force string conversion */
        }
        j = SvCUR(sv);
@@ -1426,8 +1416,7 @@ PP(pp_leavewrite)
     }
     else {
        if ((IoLINES_LEFT(io) -= FmLINES(PL_formtarget)) < 0) {
-           if (ckWARN(WARN_IO))
-               Perl_warner(aTHX_ packWARN(WARN_IO), "page overflow");
+           Perl_ck_warner(aTHX_ packWARN(WARN_IO), "page overflow");
        }
        if (!do_print(PL_formtarget, fp))
            PUSHs(&PL_sv_no);
@@ -1928,7 +1917,7 @@ PP(pp_send)
                    DIE(aTHX_ "Offset outside string");
                }
                offset += blen_chars;
-           } else if (offset >= (IV)blen_chars && blen_chars > 0) {
+           } else if (offset >= (IV)blen_chars) {
                Safefree(tmpbuf);
                DIE(aTHX_ "Offset outside string");
            }
@@ -2099,6 +2088,12 @@ PP(pp_tell)
            RETURN;
        }
     }
+    else if (!gv) {
+       if (!errno)
+           SETERRNO(EBADF,RMS_IFI);
+       PUSHi(-1);
+       RETURN;
+    }
 
 #if LSEEKSIZE > IVSIZE
     PUSHn( do_tell(gv) );
@@ -2825,9 +2820,8 @@ PP(pp_stat)
        if (PL_op->op_type == OP_LSTAT) {
            if (gv != PL_defgv) {
            do_fstat_warning_check:
-               if (ckWARN(WARN_IO))
-                   Perl_warner(aTHX_ packWARN(WARN_IO),
-                       "lstat() on filehandle %s", gv ? GvENAME(gv) : "");
+               Perl_ck_warner(aTHX_ packWARN(WARN_IO),
+                              "lstat() on filehandle %s", gv ? GvENAME(gv) : "");
            } else if (PL_laststype != OP_LSTAT)
                Perl_croak(aTHX_ "The stat preceding lstat() wasn't an lstat");
        }
@@ -2983,8 +2977,19 @@ PP(pp_ftrread)
     int stat_mode = S_IRUSR;
 
     bool effective = FALSE;
+    char opchar = '?';
     dSP;
 
+    switch (PL_op->op_type) {
+    case OP_FTRREAD:   opchar = 'R'; break;
+    case OP_FTRWRITE:  opchar = 'W'; break;
+    case OP_FTREXEC:   opchar = 'X'; break;
+    case OP_FTEREAD:   opchar = 'r'; break;
+    case OP_FTEWRITE:  opchar = 'w'; break;
+    case OP_FTEEXEC:   opchar = 'x'; break;
+    }
+    tryAMAGICftest(opchar);
+
     STACKED_FTEST_CHECK;
 
     switch (PL_op->op_type) {
@@ -3017,7 +3022,7 @@ PP(pp_ftrread)
        access_mode = W_OK;
 #endif
        stat_mode = S_IWUSR;
-       /* Fall through  */
+       /* fall through */
 
     case OP_FTEREAD:
 #ifndef PERL_EFF_ACCESS
@@ -3077,8 +3082,20 @@ PP(pp_ftis)
     dVAR;
     I32 result;
     const int op_type = PL_op->op_type;
+    char opchar = '?';
     dSP;
+
+    switch (op_type) {
+    case OP_FTIS:      opchar = 'e'; break;
+    case OP_FTSIZE:    opchar = 's'; break;
+    case OP_FTMTIME:   opchar = 'M'; break;
+    case OP_FTCTIME:   opchar = 'C'; break;
+    case OP_FTATIME:   opchar = 'A'; break;
+    }
+    tryAMAGICftest(opchar);
+
     STACKED_FTEST_CHECK;
+
     result = my_stat();
     SPAGAIN;
     if (result < 0)
@@ -3115,8 +3132,25 @@ PP(pp_ftrowned)
 {
     dVAR;
     I32 result;
+    char opchar = '?';
     dSP;
 
+    switch (PL_op->op_type) {
+    case OP_FTROWNED:  opchar = 'O'; break;
+    case OP_FTEOWNED:  opchar = 'o'; break;
+    case OP_FTZERO:    opchar = 'z'; break;
+    case OP_FTSOCK:    opchar = 'S'; break;
+    case OP_FTCHR:     opchar = 'c'; break;
+    case OP_FTBLK:     opchar = 'b'; break;
+    case OP_FTFILE:    opchar = 'f'; break;
+    case OP_FTDIR:     opchar = 'd'; break;
+    case OP_FTPIPE:    opchar = 'p'; break;
+    case OP_FTSUID:    opchar = 'u'; break;
+    case OP_FTSGID:    opchar = 'g'; break;
+    case OP_FTSVTX:    opchar = 'k'; break;
+    }
+    tryAMAGICftest(opchar);
+
     /* I believe that all these three are likely to be defined on most every
        system these days.  */
 #ifndef S_ISUID
@@ -3133,6 +3167,7 @@ PP(pp_ftrowned)
 #endif
 
     STACKED_FTEST_CHECK;
+
     result = my_stat();
     SPAGAIN;
     if (result < 0)
@@ -3199,8 +3234,13 @@ PP(pp_ftrowned)
 PP(pp_ftlink)
 {
     dVAR;
-    I32 result = my_lstat();
     dSP;
+    I32 result;
+
+    tryAMAGICftest('l');
+    result = my_lstat();
+    SPAGAIN;
+
     if (result < 0)
        RETPUSHUNDEF;
     if (S_ISLNK(PL_statcache.st_mode))
@@ -3216,6 +3256,8 @@ PP(pp_fttty)
     GV *gv;
     SV *tmpsv = NULL;
 
+    tryAMAGICftest('t');
+
     STACKED_FTEST_CHECK;
 
     if (PL_op->op_flags & OPf_REF)
@@ -3265,6 +3307,8 @@ PP(pp_fttext)
     GV *gv;
     PerlIO *fp;
 
+    tryAMAGICftest(PL_op->op_type == OP_FTTEXT ? 'T' : 'B');
+
     STACKED_FTEST_CHECK;
 
     if (PL_op->op_flags & OPf_REF)
@@ -3784,9 +3828,9 @@ PP(pp_open_dir)
     if (!io)
        goto nope;
 
-    if ((IoIFP(io) || IoOFP(io)) && ckWARN2(WARN_IO, WARN_DEPRECATED))
-       Perl_warner(aTHX_ packWARN2(WARN_IO, WARN_DEPRECATED),
-               "Opening filehandle %s also as a directory", GvENAME(gv));
+    if ((IoIFP(io) || IoOFP(io)))
+       Perl_ck_warner(aTHX_ packWARN2(WARN_IO, WARN_DEPRECATED),
+                      "Opening filehandle %s also as a directory", GvENAME(gv));
     if (IoDIRP(io))
        PerlDir_close(IoDIRP(io));
     if (!(IoDIRP(io) = PerlDir_open(dirname)))
@@ -3820,10 +3864,8 @@ PP(pp_readdir)
     register IO * const io = GvIOn(gv);
 
     if (!io || !IoDIRP(io)) {
-        if(ckWARN(WARN_IO)) {
-            Perl_warner(aTHX_ packWARN(WARN_IO),
-                "readdir() attempted on invalid dirhandle %s", GvENAME(gv));
-        }
+       Perl_ck_warner(aTHX_ packWARN(WARN_IO),
+                      "readdir() attempted on invalid dirhandle %s", GvENAME(gv));
         goto nope;
     }
 
@@ -3873,10 +3915,8 @@ PP(pp_telldir)
     register IO * const io = GvIOn(gv);
 
     if (!io || !IoDIRP(io)) {
-        if(ckWARN(WARN_IO)) {
-            Perl_warner(aTHX_ packWARN(WARN_IO),
-               "telldir() attempted on invalid dirhandle %s", GvENAME(gv));
-        }
+       Perl_ck_warner(aTHX_ packWARN(WARN_IO),
+                      "telldir() attempted on invalid dirhandle %s", GvENAME(gv));
         goto nope;
     }
 
@@ -3900,10 +3940,8 @@ PP(pp_seekdir)
     register IO * const io = GvIOn(gv);
 
     if (!io || !IoDIRP(io)) {
-       if(ckWARN(WARN_IO)) {
-           Perl_warner(aTHX_ packWARN(WARN_IO),
-                "seekdir() attempted on invalid dirhandle %s", GvENAME(gv));
-        }
+       Perl_ck_warner(aTHX_ packWARN(WARN_IO),
+                      "seekdir() attempted on invalid dirhandle %s", GvENAME(gv));
         goto nope;
     }
     (void)PerlDir_seek(IoDIRP(io), along);
@@ -3926,10 +3964,8 @@ PP(pp_rewinddir)
     register IO * const io = GvIOn(gv);
 
     if (!io || !IoDIRP(io)) {
-       if(ckWARN(WARN_IO)) {
-           Perl_warner(aTHX_ packWARN(WARN_IO),
-               "rewinddir() attempted on invalid dirhandle %s", GvENAME(gv));
-       }
+       Perl_ck_warner(aTHX_ packWARN(WARN_IO),
+                      "rewinddir() attempted on invalid dirhandle %s", GvENAME(gv));
        goto nope;
     }
     (void)PerlDir_rewind(IoDIRP(io));
@@ -3951,10 +3987,8 @@ PP(pp_closedir)
     register IO * const io = GvIOn(gv);
 
     if (!io || !IoDIRP(io)) {
-       if(ckWARN(WARN_IO)) {
-           Perl_warner(aTHX_ packWARN(WARN_IO),
-                "closedir() attempted on invalid dirhandle %s", GvENAME(gv));
-        }
+       Perl_ck_warner(aTHX_ packWARN(WARN_IO),
+                      "closedir() attempted on invalid dirhandle %s", GvENAME(gv));
         goto nope;
     }
 #ifdef VOID_CLOSEDIR
@@ -4026,7 +4060,7 @@ PP(pp_fork)
 
 PP(pp_wait)
 {
-#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL) && !defined(__LIBCATAMOUNT__)
+#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(__LIBCATAMOUNT__)
     dVAR; dSP; dTARGET;
     Pid_t childpid;
     int argflags;
@@ -4054,7 +4088,7 @@ PP(pp_wait)
 
 PP(pp_waitpid)
 {
-#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL) && !defined(__LIBCATAMOUNT__)
+#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(__LIBCATAMOUNT__)
     dVAR; dSP; dTARGET;
     const int optype = POPi;
     const Pid_t pid = TOPi;
@@ -4424,15 +4458,9 @@ PP(pp_gmtime)
 {
     dVAR;
     dSP;
-#if defined(PERL_MICRO) || !defined(Quad_t)
-    Time_t when;
-    const struct tm *err;
-    struct tm tmbuf;
-#else
     Time64_T when;
     struct TM tmbuf;
     struct TM *err;
-#endif
     const char *opname = PL_op->op_type == OP_LOCALTIME ? "localtime" : "gmtime";
     static const char * const dayname[] =
        {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
@@ -4440,48 +4468,29 @@ PP(pp_gmtime)
        {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
 
-#if defined(PERL_MICRO) || !defined(Quad_t)
-    if (MAXARG < 1)
-       (void)time(&when);
-    else
-       when = (Time_t)SvIVx(POPs);
-
-    if (PL_op->op_type == OP_LOCALTIME)
-       err = localtime(&when);
-    else
-       err = gmtime(&when);
-
-    if (!err)
-       tmbuf = *err;
-#else
     if (MAXARG < 1) {
        time_t now;
        (void)time(&now);
        when = (Time64_T)now;
     }
     else {
-       /* XXX POPq uses an SvIV so it won't work with 32 bit integer scalars
-          using a double causes an unfortunate loss of accuracy on high numbers.
-          What we really need is an SvQV.
-       */
        double input = Perl_floor(POPn);
        when = (Time64_T)input;
-       if (when != input && ckWARN(WARN_OVERFLOW)) {
-           Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
-                       "%s(%.0f) too large", opname, input);
+       if (when != input) {
+           Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW),
+                          "%s(%.0f) too large", opname, input);
        }
     }
 
     if (PL_op->op_type == OP_LOCALTIME)
-        err = localtime64_r(&when, &tmbuf);
+        err = S_localtime64_r(&when, &tmbuf);
     else
-       err = gmtime64_r(&when, &tmbuf);
-#endif
+       err = S_gmtime64_r(&when, &tmbuf);
 
-    if (err == NULL && ckWARN(WARN_OVERFLOW)) {
+    if (err == NULL) {
        /* XXX %lld broken for quads */
-       Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
-                   "%s(%.0f) failed", opname, (double)when);
+       Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW),
+                      "%s(%.0f) failed", opname, (double)when);
     }
 
     if (GIMME != G_ARRAY) {    /* scalar context */