This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Need to pass a my_perl to S_my_localtime to make threaded builds build.
[perl5.git] / pp_sys.c
index 3c0b56a..18c860b 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -201,6 +201,15 @@ void endservent(void);
 #undef PERL_EFF_ACCESS_W_OK
 #undef PERL_EFF_ACCESS_X_OK
 
+/* AIX 5.2 and below use mktime for localtime, and defines the edge case
+ * for time 0x7fffffff to be valid only in UTC. AIX 5.3 provides localtime64
+ * available in the 32bit environment, which could warrant Configure
+ * checks in the future.
+ */
+#ifdef  _AIX
+#define LOCALTIME_EDGECASE_BROKEN
+#endif
+
 /* F_OK unused: if stat() cannot find it... */
 
 #if !defined(PERL_EFF_ACCESS_R_OK) && defined(HAS_ACCESS) && defined(EFF_ONLY_OK) && !defined(NO_EFF_ONLY_OK)
@@ -321,8 +330,7 @@ PP(pp_backtick)
 {
     dSP; dTARGET;
     PerlIO *fp;
-    STRLEN n_a;
-    const char *tmps = POPpconstx;
+    const char * const tmps = POPpconstx;
     const I32 gimme = GIMME_V;
     const char *mode = "r";
 
@@ -343,7 +351,6 @@ PP(pp_backtick)
        if (gimme == G_VOID) {
            char tmpbuf[256];
            while (PerlIO_read(fp, tmpbuf, sizeof tmpbuf) > 0)
-               /*SUPPRESS 530*/
                ;
        }
        else if (gimme == G_SCALAR) {
@@ -352,17 +359,14 @@ PP(pp_backtick)
            PL_rs = &PL_sv_undef;
            sv_setpvn(TARG, "", 0);     /* note that this preserves previous buffer */
            while (sv_gets(TARG, fp, SvCUR(TARG)) != Nullch)
-               /*SUPPRESS 530*/
                ;
            LEAVE;
            XPUSHs(TARG);
            SvTAINTED_on(TARG);
        }
        else {
-           SV *sv;
-
            for (;;) {
-               sv = NEWSV(56, 79);
+               SV * const sv = NEWSV(56, 79);
                if (sv_gets(sv, fp, 0) == Nullch) {
                    SvREFCNT_dec(sv);
                    break;
@@ -448,7 +452,7 @@ PP(pp_warn)
     }
     tmps = SvPV_const(tmpsv, len);
     if ((!tmps || !len) && PL_errgv) {
-       SV *error = ERRSV;
+       SV * const error = ERRSV;
        SvUPGRADE(error, SVt_PV);
        if (SvPOK(error) && SvCUR(error))
            sv_catpv(error, "\t...caught");
@@ -885,7 +889,7 @@ PP(pp_untie)
        RETPUSHYES;
 
     if ((mg = SvTIED_mg(sv, how))) {
-       SV *obj = SvRV(SvTIED_obj(sv, mg));
+       SV * const obj = SvRV(SvTIED_obj(sv, mg));
        GV *gv;
        CV *cv = NULL;
         if (obj) {
@@ -915,7 +919,7 @@ PP(pp_untie)
 PP(pp_tied)
 {
     dSP;
-    MAGIC *mg;
+    const MAGIC *mg;
     SV *sv = POPs;
     const char how = (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV)
                ? PERL_MAGIC_tied : PERL_MAGIC_tiedscalar;
@@ -936,13 +940,12 @@ PP(pp_tied)
 PP(pp_dbmopen)
 {
     dVAR; dSP;
-    HV *hv;
     dPOPPOPssrl;
     HV* stash;
     GV *gv;
     SV *sv;
 
-    hv = (HV*)POPs;
+    HV * const hv = (HV*)POPs;
 
     sv = sv_mortalcopy(&PL_sv_no);
     sv_setpv(sv, "AnyDBM_File");
@@ -1010,7 +1013,6 @@ PP(pp_sselect)
     struct timeval *tbuf = &timebuf;
     I32 growsize;
     char *fd_sets[4];
-    STRLEN n_a;
 #if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
        I32 masksize;
        I32 offset;
@@ -1026,9 +1028,16 @@ PP(pp_sselect)
 
     SP -= 4;
     for (i = 1; i <= 3; i++) {
-       if (!SvPOK(SP[i]))
+       SV *sv = SP[i];
+       if (SvOK(sv) && SvREADONLY(sv)) {
+           if (SvIsCOW(sv))
+               sv_force_normal_flags(sv, 0);
+           if (SvREADONLY(sv))
+               DIE(aTHX_ PL_no_modify);
+       }
+       if (!SvPOK(sv))
            continue;
-       j = SvCUR(SP[i]);
+       j = SvCUR(sv);
        if (maxlen < j)
            maxlen = j;
     }
@@ -1082,7 +1091,7 @@ PP(pp_sselect)
            continue;
        }
        else if (!SvPOK(sv))
-           SvPV_force(sv,n_a); /* force string conversion */
+           SvPV_force_nolen(sv);       /* force string conversion */
        j = SvLEN(sv);
        if (j < growsize) {
            Sv_Grow(sv, growsize);
@@ -1178,7 +1187,7 @@ PP(pp_select)
     if (! hv)
        XPUSHs(&PL_sv_undef);
     else {
-       GV **gvp = (GV**)hv_fetch(hv, GvNAME(egv), GvNAMELEN(egv), FALSE);
+       GV ** const gvp = (GV**)hv_fetch(hv, GvNAME(egv), GvNAMELEN(egv), FALSE);
        if (gvp && *gvp == egv) {
            gv_efullname4(TARG, PL_defoutgv, Nullch, TRUE);
            XPUSHTARG;
@@ -1200,14 +1209,9 @@ PP(pp_select)
 PP(pp_getc)
 {
     dVAR; dSP; dTARGET;
-    GV *gv;
     IO *io = NULL;
     MAGIC *mg;
-
-    if (MAXARG == 0)
-       gv = PL_stdingv;
-    else
-       gv = (GV*)POPs;
+    GV * const gv = (MAXARG==0) ? PL_stdingv : (GV*)POPs;
 
     if (gv && (io = GvIO(gv))
        && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar)))
@@ -1319,13 +1323,15 @@ PP(pp_enterwrite)
 PP(pp_leavewrite)
 {
     dVAR; dSP;
-    GV *gv = cxstack[cxstack_ix].blk_sub.gv;
-    register IO *io = GvIOp(gv);
-    PerlIO *ofp = IoOFP(io);
+    GV * const gv = cxstack[cxstack_ix].blk_sub.gv;
+    register IO * const io = GvIOp(gv);
+    PerlIO * const ofp = IoOFP(io);
     PerlIO *fp;
     SV **newsp;
     I32 gimme;
     register PERL_CONTEXT *cx;
+    PERL_UNUSED_VAR(newsp);
+    PERL_UNUSED_VAR(gimme);
 
     DEBUG_f(PerlIO_printf(Perl_debug_log, "left=%ld, todo=%ld\n",
          (long)IoLINES_LEFT(io), (long)FmLINES(PL_formtarget)));
@@ -1338,9 +1344,9 @@ PP(pp_leavewrite)
        CV *cv;
        if (!IoTOP_GV(io)) {
            GV *topgv;
-           SV *topname;
 
            if (!IoTOP_NAME(io)) {
+               SV *topname;
                if (!IoFMT_NAME(io))
                    IoFMT_NAME(io) = savepv(GvNAME(gv));
                topname = sv_2mortal(Perl_newSVpvf(aTHX_ "%s_TOP", GvNAME(gv)));
@@ -1519,19 +1525,14 @@ PP(pp_prtf)
 PP(pp_sysopen)
 {
     dSP;
-    GV *gv;
-    SV *sv;
-    const char *tmps;
-    STRLEN len;
     const int perm = (MAXARG > 3) ? POPi : 0666;
     const int mode = POPi;
-
-    sv = POPs;
-    gv = (GV *)POPs;
+    SV * const sv = POPs;
+    GV * const gv = (GV *)POPs;
+    STRLEN len;
 
     /* Need TIEHANDLE method ? */
-
-    tmps = SvPV_const(sv, len);
+    const char * const tmps = SvPV_const(sv, len);
     /* FIXME? do_open should do const  */
     if (do_open(gv, (char*)tmps, len, TRUE, mode, perm, Nullfp)) {
        IoLINES(GvIOp(gv)) = 0;
@@ -1547,7 +1548,6 @@ PP(pp_sysread)
 {
     dVAR; dSP; dMARK; dORIGMARK; dTARGET;
     int offset;
-    GV *gv;
     IO *io;
     char *buffer;
     SSize_t length;
@@ -1555,7 +1555,6 @@ PP(pp_sysread)
     Sock_size_t bufsize;
     SV *bufsv;
     STRLEN blen;
-    MAGIC *mg;
     int fp_utf8;
     int buffer_utf8;
     SV *read_target;
@@ -1565,23 +1564,24 @@ PP(pp_sysread)
     STRLEN charskip = 0;
     STRLEN skip = 0;
 
-    gv = (GV*)*++MARK;
+    GV * const gv = (GV*)*++MARK;
     if ((PL_op->op_type == OP_READ || PL_op->op_type == OP_SYSREAD)
-       && gv && (io = GvIO(gv))
-       && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar)))
+       && gv && (io = GvIO(gv)) )
     {
-       SV *sv;
-       
-       PUSHMARK(MARK-1);
-       *MARK = SvTIED_obj((SV*)io, mg);
-       ENTER;
-       call_method("READ", G_SCALAR);
-       LEAVE;
-       SPAGAIN;
-       sv = POPs;
-       SP = ORIGMARK;
-       PUSHs(sv);
-       RETURN;
+       const MAGIC * mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar);
+       if (mg) {
+           SV *sv;
+           PUSHMARK(MARK-1);
+           *MARK = SvTIED_obj((SV*)io, mg);
+           ENTER;
+           call_method("READ", G_SCALAR);
+           LEAVE;
+           SPAGAIN;
+           sv = POPs;
+           SP = ORIGMARK;
+           PUSHs(sv);
+           RETURN;
+       }
     }
 
     if (!gv)
@@ -2432,7 +2432,8 @@ PP(pp_bind)
     extern void GETUSERMODE();
 #endif
     SV *addrsv = POPs;
-    char *addr;
+    /* OK, so on what platform does bind modify addr?  */
+    const char *addr;
     GV *gv = (GV*)POPs;
     register IO *io = GvIOn(gv);
     STRLEN len;
@@ -2444,7 +2445,7 @@ PP(pp_bind)
     if (!io || !IoIFP(io))
        goto nuts;
 
-    addr = SvPV(addrsv, len);
+    addr = SvPV_const(addrsv, len);
     TAINT_PROPER("bind");
 #ifdef MPE /* Deal with MPE bind() peculiarities */
     if (((struct sockaddr *)addr)->sa_family == AF_INET) {
@@ -2487,7 +2488,7 @@ PP(pp_connect)
 #ifdef HAS_SOCKET
     dSP;
     SV *addrsv = POPs;
-    char *addr;
+    const char *addr;
     GV *gv = (GV*)POPs;
     register IO *io = GvIOn(gv);
     STRLEN len;
@@ -2495,7 +2496,7 @@ PP(pp_connect)
     if (!io || !IoIFP(io))
        goto nuts;
 
-    addr = SvPV(addrsv, len);
+    addr = SvPV_const(addrsv, len);
     TAINT_PROPER("connect");
     if (PerlSock_connect(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
        RETPUSHYES;
@@ -2682,16 +2683,16 @@ PP(pp_ssockopt)
        PUSHs(sv);
        break;
     case OP_SSOCKOPT: {
-           char *buf;
+           const char *buf;
            int aint;
            if (SvPOKp(sv)) {
                STRLEN l;
-               buf = SvPV(sv, l);
+               buf = SvPV_const(sv, l);
                len = l;
            }
            else {
                aint = (int)SvIV(sv);
-               buf = (char*)&aint;
+               buf = (const char*)&aint;
                len = sizeof(int);
            }
            if (PerlSock_setsockopt(fd, lvl, optname, buf, len) < 0)
@@ -2755,8 +2756,8 @@ PP(pp_getpeername)
        {
            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,
+           if (((struct sockaddr *)SvPVX_const(sv))->sa_family == AF_INET &&
+               !memcmp((char *)SvPVX_const(sv) + sizeof(u_short), nowhere,
                        sizeof(u_short) + sizeof(struct in_addr))) {
                goto nuts2;     
            }
@@ -2800,7 +2801,6 @@ PP(pp_stat)
     GV *gv;
     I32 gimme;
     I32 max = 13;
-    STRLEN n_a;
 
     if (PL_op->op_flags & OPf_REF) {
        gv = cGVOP_gv;
@@ -2840,15 +2840,15 @@ PP(pp_stat)
                        "lstat() on filehandle %s", GvENAME(gv));
            goto do_fstat;
        }
-       sv_setpv(PL_statname, SvPV_const(sv,n_a));
+       sv_setpv(PL_statname, SvPV_nolen_const(sv));
        PL_statgv = Nullgv;
        PL_laststype = PL_op->op_type;
        if (PL_op->op_type == OP_LSTAT)
-           PL_laststatval = PerlLIO_lstat(SvPV(PL_statname, n_a), &PL_statcache);
+           PL_laststatval = PerlLIO_lstat(SvPV_nolen_const(PL_statname), &PL_statcache);
        else
-           PL_laststatval = PerlLIO_stat(SvPV(PL_statname, n_a), &PL_statcache);
+           PL_laststatval = PerlLIO_stat(SvPV_nolen_const(PL_statname), &PL_statcache);
        if (PL_laststatval < 0) {
-           if (ckWARN(WARN_NEWLINE) && strchr(SvPV(PL_statname, n_a), '\n'))
+           if (ckWARN(WARN_NEWLINE) && strchr(SvPV_nolen_const(PL_statname), '\n'))
                Perl_warner(aTHX_ packWARN(WARN_NEWLINE), PL_warn_nl, "stat");
            max = 0;
        }
@@ -2931,7 +2931,6 @@ PP(pp_ftrread)
     STACKED_FTEST_CHECK;
 #if defined(HAS_ACCESS) && defined(R_OK)
     if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
-       STRLEN n_a;
        result = access(POPpx, R_OK);
        if (result == 0)
            RETPUSHYES;
@@ -2959,7 +2958,6 @@ PP(pp_ftrwrite)
     STACKED_FTEST_CHECK;
 #if defined(HAS_ACCESS) && defined(W_OK)
     if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
-       STRLEN n_a;
        result = access(POPpx, W_OK);
        if (result == 0)
            RETPUSHYES;
@@ -2987,7 +2985,6 @@ PP(pp_ftrexec)
     STACKED_FTEST_CHECK;
 #if defined(HAS_ACCESS) && defined(X_OK)
     if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
-       STRLEN n_a;
        result = access(POPpx, X_OK);
        if (result == 0)
            RETPUSHYES;
@@ -3015,7 +3012,6 @@ PP(pp_fteread)
     STACKED_FTEST_CHECK;
 #ifdef PERL_EFF_ACCESS_R_OK
     if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
-       STRLEN n_a;
        result = PERL_EFF_ACCESS_R_OK(POPpx);
        if (result == 0)
            RETPUSHYES;
@@ -3043,7 +3039,6 @@ PP(pp_ftewrite)
     STACKED_FTEST_CHECK;
 #ifdef PERL_EFF_ACCESS_W_OK
     if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
-       STRLEN n_a;
        result = PERL_EFF_ACCESS_W_OK(POPpx);
        if (result == 0)
            RETPUSHYES;
@@ -3071,7 +3066,6 @@ PP(pp_fteexec)
     STACKED_FTEST_CHECK;
 #ifdef PERL_EFF_ACCESS_X_OK
     if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
-       STRLEN n_a;
        result = PERL_EFF_ACCESS_X_OK(POPpx);
        if (result == 0)
            RETPUSHYES;
@@ -3358,8 +3352,7 @@ PP(pp_fttty)
     if (GvIO(gv) && IoIFP(GvIOp(gv)))
        fd = PerlIO_fileno(IoIFP(GvIOp(gv)));
     else if (tmpsv && SvOK(tmpsv)) {
-       STRLEN n_a;
-       char *tmps = SvPV(tmpsv, n_a);
+       const char *tmps = SvPV_nolen_const(tmpsv);
        if (isDIGIT(*tmps))
            fd = atoi(tmps);
        else 
@@ -3391,7 +3384,6 @@ PP(pp_fttext)
     register IO *io;
     register SV *sv;
     GV *gv;
-    STRLEN n_a;
     PerlIO *fp;
 
     STACKED_FTEST_CHECK;
@@ -3460,9 +3452,10 @@ PP(pp_fttext)
       really_filename:
        PL_statgv = Nullgv;
        PL_laststype = OP_STAT;
-       sv_setpv(PL_statname, SvPV(sv, n_a));
+       sv_setpv(PL_statname, SvPV_nolen_const(sv));
        if (!(fp = PerlIO_open(SvPVX_const(PL_statname), "r"))) {
-           if (ckWARN(WARN_NEWLINE) && strchr(SvPV(PL_statname, n_a), '\n'))
+           if (ckWARN(WARN_NEWLINE) && strchr(SvPV_nolen_const(PL_statname),
+                                              '\n'))
                Perl_warner(aTHX_ packWARN(WARN_NEWLINE), PL_warn_nl, "open");
            RETPUSHUNDEF;
        }
@@ -3548,7 +3541,6 @@ PP(pp_chdir)
     dSP; dTARGET;
     const char *tmps;
     SV **svp;
-    STRLEN n_a;
 
     if( MAXARG == 1 )
         tmps = POPpconstx;
@@ -3565,7 +3557,7 @@ PP(pp_chdir)
         {
             if( MAXARG == 1 )
                 deprecate("chdir('') or chdir(undef) as chdir()");
-            tmps = SvPV_const(*svp, n_a);
+            tmps = SvPV_nolen_const(*svp);
         }
         else {
             PUSHi(0);
@@ -3602,7 +3594,6 @@ PP(pp_chroot)
 {
 #ifdef HAS_CHROOT
     dSP; dTARGET;
-    STRLEN n_a;
     char *tmps = POPpx;
     TAINT_PROPER("chroot");
     PUSHi( chroot(tmps) >= 0 );
@@ -3646,7 +3637,6 @@ PP(pp_rename)
 {
     dSP; dTARGET;
     int anum;
-    STRLEN n_a;
     const char *tmps2 = POPpconstx;
     const char *tmps = SvPV_nolen_const(TOPs);
     TAINT_PROPER("rename");
@@ -3672,7 +3662,6 @@ PP(pp_link)
 {
 #ifdef HAS_LINK
     dSP; dTARGET;
-    STRLEN n_a;
     const char *tmps2 = POPpconstx;
     const char *tmps = SvPV_nolen_const(TOPs);
     TAINT_PROPER("link");
@@ -3687,7 +3676,6 @@ PP(pp_symlink)
 {
 #ifdef HAS_SYMLINK
     dSP; dTARGET;
-    STRLEN n_a;
     const char *tmps2 = POPpconstx;
     const char *tmps = SvPV_nolen_const(TOPs);
     TAINT_PROPER("symlink");
@@ -3706,7 +3694,6 @@ PP(pp_readlink)
     const char *tmps;
     char buf[MAXPATHLEN];
     int len;
-    STRLEN n_a;
 
 #ifndef INCOMPLETE_TAINTS
     TAINT;
@@ -3888,7 +3875,6 @@ PP(pp_open_dir)
 {
 #if defined(Direntry_t) && defined(HAS_READDIR)
     dSP;
-    STRLEN n_a;
     const char *dirname = POPpconstx;
     GV *gv = (GV*)POPs;
     register IO *io = GvIOn(gv);
@@ -4079,7 +4065,6 @@ PP(pp_fork)
     if (childpid < 0)
        RETSETUNDEF;
     if (!childpid) {
-       /*SUPPRESS 560*/
        if ((tmpgv = gv_fetchpv("$", TRUE, SVt_PV))) {
             SvREADONLY_off(GvSV(tmpgv));
            sv_setiv(GvSV(tmpgv), (IV)PerlProc_getpid());
@@ -4174,7 +4159,6 @@ PP(pp_system)
 {
     dSP; dMARK; dORIGMARK; dTARGET;
     I32 value;
-    STRLEN n_a;
     int result;
 
     if (PL_tainting) {
@@ -4265,7 +4249,7 @@ PP(pp_system)
        else if (SP - MARK != 1)
            value = (I32)do_aexec5(Nullsv, MARK, SP, pp[1], did_pipes);
        else {
-           value = (I32)do_exec3(SvPVx(sv_mortalcopy(*SP), n_a), pp[1], did_pipes);
+           value = (I32)do_exec3(SvPVx_nolen(sv_mortalcopy(*SP)), pp[1], did_pipes);
        }
        PerlProc__exit(-1);
     }
@@ -4288,7 +4272,7 @@ PP(pp_system)
 #  endif
     }
     else {
-       value = (I32)do_spawn(SvPVx(sv_mortalcopy(*SP), n_a));
+       value = (I32)do_spawn(SvPVx_nolen(sv_mortalcopy(*SP)));
     }
     if (PL_statusvalue == -1)  /* hint that value must be returned as is */
        result = 1;
@@ -4304,7 +4288,6 @@ PP(pp_exec)
 {
     dSP; dMARK; dORIGMARK; dTARGET;
     I32 value;
-    STRLEN n_a;
 
     if (PL_tainting) {
        TAINT_ENV();
@@ -4336,13 +4319,13 @@ PP(pp_exec)
 #endif
     else {
 #ifdef VMS
-       value = (I32)vms_do_exec(SvPVx(sv_mortalcopy(*SP), n_a));
+       value = (I32)vms_do_exec(SvPVx_nolen(sv_mortalcopy(*SP)));
 #else
 #  ifdef __OPEN_VM
-       (void) do_spawn(SvPVx(sv_mortalcopy(*SP), n_a));
+       (void) do_spawn(SvPVx_nolen(sv_mortalcopy(*SP)));
        value = 0;
 #  else
-       value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), n_a));
+       value = (I32)do_exec(SvPVx_nolen(sv_mortalcopy(*SP)));
 #  endif
 #endif
     }
@@ -4524,6 +4507,44 @@ PP(pp_localtime)
     return pp_gmtime();
 }
 
+#ifdef LOCALTIME_EDGECASE_BROKEN
+static struct tm *S_my_localtime (pTHX_ Time_t *tp)
+{
+    auto time_t     T;
+    auto struct tm *P;
+
+    /* No workarounds in the valid range */
+    if (!tp || *tp < 0x7fff573f || *tp >= 0x80000000)
+       return (localtime (tp));
+
+    /* This edge case is to workaround the undefined behaviour, where the
+     * TIMEZONE makes the time go beyond the defined range.
+     * gmtime (0x7fffffff) => 2038-01-19 03:14:07
+     * If there is a negative offset in TZ, like MET-1METDST, some broken
+     * implementations of localtime () (like AIX 5.2) barf with bogus
+     * return values:
+     * 0x7fffffff gmtime               2038-01-19 03:14:07
+     * 0x7fffffff localtime            1901-12-13 21:45:51
+     * 0x7fffffff mylocaltime          2038-01-19 04:14:07
+     * 0x3c19137f gmtime               2001-12-13 20:45:51
+     * 0x3c19137f localtime            2001-12-13 21:45:51
+     * 0x3c19137f mylocaltime          2001-12-13 21:45:51
+     * Given that legal timezones are typically between GMT-12 and GMT+12
+     * we turn back the clock 23 hours before calling the localtime
+     * function, and add those to the return value. This will never cause
+     * day wrapping problems, since the edge case is Jan *19*
+     */
+    T = *tp - 82800; /* 23 hour. allows up to GMT-23 */
+    P = localtime (&T);
+    P->tm_hour += 23;
+    if (P->tm_hour >= 24) {
+       P->tm_hour -= 24;
+       P->tm_mday++;
+    }
+    return (P);
+} /* S_my_localtime */
+#endif
+
 PP(pp_gmtime)
 {
     dSP;
@@ -4545,7 +4566,11 @@ PP(pp_gmtime)
 #endif
 
     if (PL_op->op_type == OP_LOCALTIME)
+#ifdef LOCALTIME_EDGECASE_BROKEN
+       tmbuf = S_my_localtime(aTHX_ &when);
+#else
        tmbuf = localtime(&when);
+#endif
     else
        tmbuf = gmtime(&when);
 
@@ -4769,7 +4794,6 @@ PP(pp_ghostent)
 #endif
     struct hostent *hent;
     unsigned long len;
-    STRLEN n_a;
 
     EXTEND(SP, 10);
     if (which == OP_GHBYNAME) {
@@ -4885,7 +4909,6 @@ PP(pp_gnetent)
     struct netent *getnetent(void);
 #endif
     struct netent *nent;
-    STRLEN n_a;
 
     if (which == OP_GNBYNAME){
 #ifdef HAS_GETNETBYNAME
@@ -4986,7 +5009,6 @@ PP(pp_gprotoent)
     struct protoent *getprotoent(void);
 #endif
     struct protoent *pent;
-    STRLEN n_a;
 
     if (which == OP_GPBYNAME) {
 #ifdef HAS_GETPROTOBYNAME
@@ -5073,7 +5095,6 @@ PP(pp_gservent)
     struct servent *getservent(void);
 #endif
     struct servent *sent;
-    STRLEN n_a;
 
     if (which == OP_GSBYNAME) {
 #ifdef HAS_GETSERVBYNAME
@@ -5269,7 +5290,6 @@ PP(pp_gpwent)
     dSP;
     I32 which = PL_op->op_type;
     register SV *sv;
-    STRLEN n_a;
     struct passwd *pwent  = NULL;
     /*
      * We currently support only the SysV getsp* shadow password interface.
@@ -5548,7 +5568,6 @@ PP(pp_ggrent)
     register char **elem;
     register SV *sv;
     struct group *grent;
-    STRLEN n_a;
 
     if (which == OP_GGRNAM) {
         char* name = POPpbytex;
@@ -5660,7 +5679,6 @@ PP(pp_syscall)
     unsigned long a[20];
     register I32 i = 0;
     I32 retval = -1;
-    STRLEN n_a;
 
     if (PL_tainting) {
        while (++MARK <= SP) {
@@ -5683,7 +5701,7 @@ PP(pp_syscall)
        else if (*MARK == &PL_sv_undef)
            a[i++] = 0;
        else
-           a[i++] = (unsigned long)SvPV_force(*MARK, n_a);
+           a[i++] = (unsigned long)SvPV_force_nolen(*MARK);
        if (i > 15)
            break;
     }