]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Fixup strlcat and strlcpy to be a bit more descriptive 1886/head
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 14 Mar 2018 12:43:17 +0000 (08:43 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 14 Mar 2018 12:43:17 +0000 (08:43 -0400)
When I use these functions and am programming on linux I
always have to pull up a man page for these two functions
since they exist in *BSD land only.

Modify the name of the size variable to destsize on
pass in to give me the small hint I need to know
what to do.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/strlcat.c
lib/strlcpy.c
lib/zebra.h

index 8186304437e333b3be2e82bdf33e1ce8f414c20a..be211f82a8e527a8ec8e1dda6cc47e14559460ee 100644 (file)
 #ifndef HAVE_STRLCAT
 #undef strlcat
 
-size_t strlcat(char *__restrict dest, const char *__restrict src, size_t size);
+size_t strlcat(char *__restrict dest,
+              const char *__restrict src, size_t destsize);
 
-size_t strlcat(char *__restrict dest, const char *__restrict src, size_t size)
+size_t strlcat(char *__restrict dest,
+              const char *__restrict src, size_t destsize)
 {
        size_t src_length = strlen(src);
 
        /* Our implementation strlcat supports dest == NULL if size == 0
           (for consistency with snprintf and strlcpy), but strnlen does
           not, so we have to cover this case explicitly.  */
-       if (size == 0)
+       if (destsize == 0)
                return src_length;
 
-       size_t dest_length = strnlen(dest, size);
-       if (dest_length != size) {
+       size_t dest_length = strnlen(dest, destsize);
+       if (dest_length != destsize) {
                /* Copy at most the remaining number of characters in the
                   destination buffer.  Leave for the NUL terminator.  */
-               size_t to_copy = size - dest_length - 1;
+               size_t to_copy = destsize - dest_length - 1;
                /* But not more than what is available in the source string.  */
                if (to_copy > src_length)
                        to_copy = src_length;
index b7681754aa7e7fd90ca02c1a8331b8a357f0e071..b0c33ca7f42baeac4acd8dce8b9163fc5974b639 100644 (file)
 #ifndef HAVE_STRLCPY
 #undef strlcpy
 
-size_t strlcpy(char *__restrict dest, const char *__restrict src, size_t size);
+size_t strlcpy(char *__restrict dest,
+              const char *__restrict src, size_t destsize);
 
-size_t strlcpy(char *__restrict dest, const char *__restrict src, size_t size)
+size_t strlcpy(char *__restrict dest,
+              const char *__restrict src, size_t destsize)
 {
        size_t src_length = strlen(src);
 
-       if (__builtin_expect(src_length >= size, 0)) {
-               if (size > 0) {
-                       /* Copy the leading portion of the string.  The last
-                          character is subsequently overwritten with the NUL
-                          terminator, but the destination size is usually a
-                          multiple of a small power of two, so writing it twice
-                          should be more efficient than copying an odd number
-                          of
-                          bytes.  */
-                       memcpy(dest, src, size);
-                       dest[size - 1] = '\0';
+       if (__builtin_expect(src_length >= destsize, 0)) {
+               if (destsize > 0) {
+                       /*
+                        * Copy the leading portion of the string.  The last
+                        * character is subsequently overwritten with the NUL
+                        * terminator, but the destination destsize is usually
+                        * a multiple of a small power of two, so writing it
+                        * twice should be more efficient than copying an odd
+                        * number of bytes.
+                        */
+                       memcpy(dest, src, destsize);
+                       dest[destsize - 1] = '\0';
                }
        } else
                /* Copy the string and its terminating NUL character.  */
index 262ad2e43d56dec0ccf9a3d1792c326875af3fca..923f6f77c6603f46560a3c3269ee9b3fe5aaec79 100644 (file)
@@ -232,10 +232,12 @@ typedef unsigned char u_int8_t;
 #include "zassert.h"
 
 #ifndef HAVE_STRLCAT
-size_t strlcat(char *__restrict dest, const char *__restrict src, size_t size);
+size_t strlcat(char *__restrict dest,
+              const char *__restrict src, size_t destsize);
 #endif
 #ifndef HAVE_STRLCPY
-size_t strlcpy(char *__restrict dest, const char *__restrict src, size_t size);
+size_t strlcpy(char *__restrict dest,
+              const char *__restrict src, size_t destsize);
 #endif
 
 #ifdef HAVE_BROKEN_CMSG_FIRSTHDR