Change the IV to a union.
[p5sagit/p5-mst-13.2.git] / util.c
diff --git a/util.c b/util.c
index 0bff7e7..5e48418 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1008,7 +1008,7 @@ Perl_vmess(pTHX_ const char *pat, va_list *args)
            OutCopFILE(cop), (IV)CopLINE(cop));
        if (GvIO(PL_last_in_gv) && IoLINES(GvIOp(PL_last_in_gv))) {
            const bool line_mode = (RsSIMPLE(PL_rs) &&
-                             SvCUR(PL_rs) == 1 && *SvPVX(PL_rs) == '\n');
+                             SvCUR(PL_rs) == 1 && *SvPVX_const(PL_rs) == '\n');
            Perl_sv_catpvf(aTHX_ sv, ", <%s> %s %"IVdf,
                           PL_last_in_gv == PL_argvgv ?
                           "" : GvNAME(PL_last_in_gv),
@@ -1361,10 +1361,10 @@ Perl_vwarner(pTHX_ U32  err, const char* pat, va_list* args)
 {
     dVAR;
     if (ckDEAD(err)) {
-       SV *msv = vmess(pat, args);
+       SV * const msv = vmess(pat, args);
        STRLEN msglen;
        const char *message = SvPV(msv, msglen);
-       I32 utf8 = SvUTF8(msv);
+       const I32 utf8 = SvUTF8(msv);
 
        if (PL_diehook) {
            assert(message);
@@ -2710,7 +2710,7 @@ Perl_repeatcpy(pTHX_ register char *to, register const char *from, I32 len, regi
 
 #ifndef HAS_RENAME
 I32
-Perl_same_dirent(pTHX_ char *a, char *b)
+Perl_same_dirent(pTHX_ const char *a, const char *b)
 {
     char *fa = strrchr(a,'/');
     char *fb = strrchr(b,'/');
@@ -2732,13 +2732,13 @@ Perl_same_dirent(pTHX_ char *a, char *b)
        sv_setpv(tmpsv, ".");
     else
        sv_setpvn(tmpsv, a, fa - a);
-    if (PerlLIO_stat(SvPVX(tmpsv), &tmpstatbuf1) < 0)
+    if (PerlLIO_stat(SvPVX_const(tmpsv), &tmpstatbuf1) < 0)
        return FALSE;
     if (fb == b)
        sv_setpv(tmpsv, ".");
     else
        sv_setpvn(tmpsv, b, fb - b);
-    if (PerlLIO_stat(SvPVX(tmpsv), &tmpstatbuf2) < 0)
+    if (PerlLIO_stat(SvPVX_const(tmpsv), &tmpstatbuf2) < 0)
        return FALSE;
     return tmpstatbuf1.st_dev == tmpstatbuf2.st_dev &&
           tmpstatbuf1.st_ino == tmpstatbuf2.st_ino;
@@ -3682,8 +3682,7 @@ Perl_getcwd_sv(pTHX_ register SV *sv)
         * size from the heap if they are given a NULL buffer pointer.
         * The problem is that this behaviour is not portable. */
        if (getcwd(buf, sizeof(buf) - 1)) {
-           STRLEN len = strlen(buf);
-           sv_setpvn(sv, buf, len);
+           sv_setpvn(sv, buf, strlen(buf));
            return TRUE;
        }
        else {
@@ -3696,8 +3695,7 @@ Perl_getcwd_sv(pTHX_ register SV *sv)
 
     Stat_t statbuf;
     int orig_cdev, orig_cino, cdev, cino, odev, oino, tdev, tino;
-    int namelen, pathlen=0;
-    DIR *dir;
+    int pathlen=0;
     Direntry_t *dp;
 
     (void)SvUPGRADE(sv, SVt_PV);
@@ -3712,6 +3710,7 @@ Perl_getcwd_sv(pTHX_ register SV *sv)
     cino = orig_cino;
 
     for (;;) {
+       DIR *dir;
        odev = cdev;
        oino = cino;
 
@@ -3734,9 +3733,9 @@ Perl_getcwd_sv(pTHX_ register SV *sv)
 
        while ((dp = PerlDir_read(dir)) != NULL) {
 #ifdef DIRNAMLEN
-           namelen = dp->d_namlen;
+           const int namelen = dp->d_namlen;
 #else
-           namelen = strlen(dp->d_name);
+           const int namelen = strlen(dp->d_name);
 #endif
            /* skip . and .. */
            if (SV_CWD_ISDOT(dp)) {
@@ -3766,7 +3765,7 @@ Perl_getcwd_sv(pTHX_ register SV *sv)
 
        if (pathlen) {
            /* shift down */
-           Move(SvPVX(sv), SvPVX(sv) + namelen + 1, pathlen, char);
+           Move(SvPVX_const(sv), SvPVX(sv) + namelen + 1, pathlen, char);
        }
 
        /* prepend current directory to the front */
@@ -3788,7 +3787,7 @@ Perl_getcwd_sv(pTHX_ register SV *sv)
        *SvEND(sv) = '\0';
        SvPOK_only(sv);
 
-       if (PerlDir_chdir(SvPVX(sv)) < 0) {
+       if (PerlDir_chdir(SvPVX_const(sv)) < 0) {
            SV_CWD_RETURN_UNDEF;
        }
     }
@@ -3970,7 +3969,7 @@ Perl_new_version(pTHX_ SV *ver)
        AvREAL_on((AV*)sv);
        for ( key = 0; key <= av_len(av); key++ )
        {
-           I32 rev = SvIV(*av_fetch(av, key, FALSE));
+           const I32 rev = SvIV(*av_fetch(av, key, FALSE));
            av_push((AV *)sv, newSViv(rev));
        }
        return rv;
@@ -4354,7 +4353,7 @@ S_socketpair_udp (int fd[2]) {
     errno = ECONNABORTED;
   tidy_up_and_fail:
     {
-       int save_errno = errno;
+       const int save_errno = errno;
        if (sockets[0] != -1)
            PerlLIO_close(sockets[0]);
        if (sockets[1] != -1)
@@ -4723,6 +4722,11 @@ Perl_init_global_struct(pTHX)
 #  else
     plvarsp = PL_VarsPtr;
 #  endif /* PERL_GLOBAL_STRUCT_PRIVATE */
+#  undef PERLVAR
+#  undef PERLVARA
+#  undef PERLVARI
+#  undef PERLVARIC
+#  undef PERLVARISC
 #  define PERLVAR(var,type) /**/
 #  define PERLVARA(var,n,type) /**/
 #  define PERLVARI(var,type,init) plvarsp->var = init;
@@ -4773,3 +4777,12 @@ Perl_free_global_struct(pTHX_ struct perl_vars *plvarsp)
 
 #endif /* PERL_GLOBAL_STRUCT */
 
+/*
+ * Local variables:
+ * c-indentation-style: bsd
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ *
+ * ex: set ts=8 sts=4 sw=4 noet:
+ */