Change 28528 by [EMAIL PROTECTED] on 2006/07/10 13:55:39

        Change existing uses of strlcpy()/strlcat() to use new my_strlcpy()/
        my_strlcat() API.  Convert ext/File/Glob/bsd_glob.c to use 
        my_strlcat().  Add to the strlcy()/strlcat() todo entry.

Affected files ...

... //depot/perl/doio.c#338 edit
... //depot/perl/ext/File/Glob/bsd_glob.c#28 edit
... //depot/perl/pod/perltodo.pod#150 edit
... //depot/perl/pp_ctl.c#572 edit
... //depot/perl/util.c#572 edit

Differences ...

==== //depot/perl/doio.c#338 (text) ====
Index: perl/doio.c
--- perl/doio.c#337~28523~      2006-07-10 03:11:22.000000000 -0700
+++ perl/doio.c 2006-07-10 06:55:39.000000000 -0700
@@ -258,17 +258,10 @@
            }
            mode[0] = 'w';
            writing = 1;
-#ifdef HAS_STRLCAT
             if (out_raw)
-                strlcat(mode, "b", PERL_MODE_MAX - 1);
+                my_strlcat(mode, "b", PERL_MODE_MAX - 1);
             else if (out_crlf)
-                strlcat(mode, "t", PERL_MODE_MAX - 1); 
-#else
-           if (out_raw)
-               strcat(mode, "b");
-           else if (out_crlf)
-               strcat(mode, "t");
-#endif
+                my_strlcat(mode, "t", PERL_MODE_MAX - 1); 
            if (num_svs > 1) {
                fp = PerlProc_popen_list(mode, num_svs, svp);
            }
@@ -296,17 +289,10 @@
            }
            writing = 1;
 
-#ifdef HAS_STRLCAT
             if (out_raw)
-                strlcat(mode, "b", PERL_MODE_MAX - 1);
+                my_strlcat(mode, "b", PERL_MODE_MAX - 1);
             else if (out_crlf)
-                strlcat(mode, "t", PERL_MODE_MAX - 1);
-#else
-           if (out_raw)
-               strcat(mode, "b");
-           else if (out_crlf)
-               strcat(mode, "t");
-#endif
+                my_strlcat(mode, "t", PERL_MODE_MAX - 1);
            if (*type == '&') {
              duplicity:
                dodup = PERLIO_DUP_FD;
@@ -429,17 +415,10 @@
                type++;
            } while (isSPACE(*type));
            mode[0] = 'r';
-#ifdef HAS_STRLCAT
             if (in_raw)
-                strlcat(mode, "b", PERL_MODE_MAX - 1);
+                my_strlcat(mode, "b", PERL_MODE_MAX - 1);
             else if (in_crlf)
-                strlcat(mode, "t", PERL_MODE_MAX - 1);
-#else
-           if (in_raw)
-               strcat(mode, "b");
-           else if (in_crlf)
-               strcat(mode, "t");
-#endif
+                my_strlcat(mode, "t", PERL_MODE_MAX - 1);
            if (*type == '&') {
                goto duplicity;
            }
@@ -490,17 +469,10 @@
            TAINT_PROPER("piped open");
            mode[0] = 'r';
 
-#ifdef HAS_STRLCAT
             if (in_raw)
-                strlcat(mode, "b", PERL_MODE_MAX - 1);
+                my_strlcat(mode, "b", PERL_MODE_MAX - 1);
             else if (in_crlf)
-                strlcat(mode, "t", PERL_MODE_MAX - 1);
-#else
-           if (in_raw)
-               strcat(mode, "b");
-           else if (in_crlf)
-               strcat(mode, "t");
-#endif
+                my_strlcat(mode, "t", PERL_MODE_MAX - 1);
 
            if (num_svs > 1) {
                fp = PerlProc_popen_list(mode,num_svs,svp);
@@ -528,17 +500,10 @@
                ;
            mode[0] = 'r';
 
-#ifdef HAS_STRLCAT
             if (in_raw)
-                strlcat(mode, "b", PERL_MODE_MAX - 1);
+                my_strlcat(mode, "b", PERL_MODE_MAX - 1);
             else if (in_crlf)
-                strlcat(mode, "t", PERL_MODE_MAX - 1);
-#else
-           if (in_raw)
-               strcat(mode, "b");
-           else if (in_crlf)
-               strcat(mode, "t");
-#endif
+                my_strlcat(mode, "t", PERL_MODE_MAX - 1);
 
            if (*name == '-' && name[1] == '\0') {
                fp = PerlIO_stdin();
@@ -1493,19 +1458,11 @@
         char flags[PERL_FLAGS_MAX];
        if (strnEQ(cmd,PL_cshname,PL_cshlen) &&
            strnEQ(cmd+PL_cshlen," -c",3)) {
-#ifdef HAS_STRLCPY
-          strlcpy(flags, "-c", PERL_FLAGS_MAX);
-#else
-         strcpy(flags,"-c");
-#endif
+          my_strlcpy(flags, "-c", PERL_FLAGS_MAX);
          s = cmd+PL_cshlen+3;
          if (*s == 'f') {
              s++;
-#ifdef HAS_STRLCPY
-              strlcat(flags, "f", PERL_FLAGS_MAX - 2);
-#else
-             strcat(flags,"f");
-#endif
+              my_strlcat(flags, "f", PERL_FLAGS_MAX - 2);
          }
          if (*s == ' ')
              s++;
@@ -2317,7 +2274,7 @@
        STRLEN len;
 
        const char *mbuf = SvPV_const(mstr, len);
-       const I32 n = ((I32)len > msize) ? msize : (I32)len;
+       const I32 n = (len > msize) ? msize : len;
        Copy(mbuf, shm + mpos, n, char);
        if (n < msize)
            memzero(shm + mpos + n, msize - n);

==== //depot/perl/ext/File/Glob/bsd_glob.c#28 (text) ====
Index: perl/ext/File/Glob/bsd_glob.c
--- perl/ext/File/Glob/bsd_glob.c#27~25101~     2005-07-08 09:35:10.000000000 
-0700
+++ perl/ext/File/Glob/bsd_glob.c       2006-07-10 06:55:39.000000000 -0700
@@ -1131,9 +1131,9 @@
 
        if (!*str) {
 #ifdef MACOS_TRADITIONAL
-               strcpy(buf, ":");
+               my_strlcpy(buf, ":", sizeof(buf));
 #else
-               strcpy(buf, ".");
+               my_strlcpy(buf, ".", sizeof(buf));
 #endif
        } else {
                if (g_Ctoc(str, buf, sizeof(buf)))

==== //depot/perl/pod/perltodo.pod#150 (text) ====
Index: perl/pod/perltodo.pod
--- perl/pod/perltodo.pod#149~28516~    2006-07-09 11:50:01.000000000 -0700
+++ perl/pod/perltodo.pod       2006-07-10 06:55:39.000000000 -0700
@@ -622,7 +622,9 @@
 
 =head2 Integrate Russ Allbery's strlcat/strlcpy implementation
 
-And remove the last remaining uses of strcat() and strcpy().
+And remove the last remaining uses of strcat() and strcpy().  Also, add
+my_strlcat() and my_strlcpy() to Devel::PPPort so previous versions of Perl can
+use these APIs. 
 
 =head1 Big projects
 

==== //depot/perl/pp_ctl.c#572 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c#571~28349~    2006-06-04 15:32:50.000000000 -0700
+++ perl/pp_ctl.c       2006-07-10 06:55:39.000000000 -0700
@@ -3423,9 +3423,7 @@
     U32 seq;
     HV *saved_hh = NULL;
     const char * const fakestr = "_<(eval )";
-#ifdef HAS_STRLCPY
     const int fakelen = 9 + 1;
-#endif
     
     if (PL_op->op_private & OPpEVAL_HAS_HH) {
        saved_hh = (HV*) SvREFCNT_inc(POPs);
@@ -3498,11 +3496,7 @@
     if (PERLDB_INTER && was != (I32)PL_sub_generation /* Some subs defined 
here. */
        && ret != PL_op->op_next) {     /* Successive compilation. */
        /* Copy in anything fake and short. */
-#ifdef HAS_STRLCPY
-       strlcpy(safestr, fakestr, fakelen);
-#else
-       strcpy(safestr, fakestr);
-#endif /* #ifdef HAS_STRLCPY */
+       my_strlcpy(safestr, fakestr, fakelen);
     }
     return DOCATCH(ret);
 }

==== //depot/perl/util.c#572 (text) ====
Index: perl/util.c
--- perl/util.c#571~28525~      2006-07-10 04:28:24.000000000 -0700
+++ perl/util.c 2006-07-10 06:55:39.000000000 -0700
@@ -3118,13 +3118,7 @@
            if (len == 2 && tmpbuf[0] == '.')
                seen_dot = 1;
 #endif
-#ifdef HAS_STRLCAT
-           (void)strlcpy(tmpbuf + len, scriptname, sizeof(tmpbuf) - len);
-#else
-           /* FIXME? Convert to memcpy by storing previous strlen(scriptname)
-            */
-           (void)strcpy(tmpbuf + len, scriptname);
-#endif /* #ifdef HAS_STRLCAT */
+           (void)my_strlcpy(tmpbuf + len, scriptname, sizeof(tmpbuf) - len);
 #endif  /* !VMS */
 
 #ifdef SEARCH_EXTS
End of Patch.

Reply via email to