diff options
author | Donald Sharp <sharpd@cumulusnetworks.com> | 2018-03-14 13:43:17 +0100 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2018-03-14 13:43:17 +0100 |
commit | c9a164dfb5ed5b96a77cd09aad76090b435c11c1 (patch) | |
tree | b516c66c12dca47467db796409951ca970c29e39 /lib/strlcpy.c | |
parent | Merge pull request #1880 from pguibert6WIND/enforce_vrf_netns_enable (diff) | |
download | frr-c9a164dfb5ed5b96a77cd09aad76090b435c11c1.tar.xz frr-c9a164dfb5ed5b96a77cd09aad76090b435c11c1.zip |
lib: Fixup strlcat and strlcpy to be a bit more descriptive
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>
Diffstat (limited to 'lib/strlcpy.c')
-rw-r--r-- | lib/strlcpy.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/strlcpy.c b/lib/strlcpy.c index b7681754a..b0c33ca7f 100644 --- a/lib/strlcpy.c +++ b/lib/strlcpy.c @@ -27,23 +27,26 @@ #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. */ |