summaryrefslogtreecommitdiff
path: root/lib/strlcpy.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/strlcpy.c')
-rw-r--r--lib/strlcpy.c44
1 files changed, 20 insertions, 24 deletions
diff --git a/lib/strlcpy.c b/lib/strlcpy.c
index 41bab97ea7..e023ca13e7 100644
--- a/lib/strlcpy.c
+++ b/lib/strlcpy.c
@@ -26,31 +26,27 @@
#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 size);
-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 size)
{
- 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';
- }
- }
- else
- /* Copy the string and its terminating NUL character. */
- memcpy (dest, src, src_length + 1);
- return src_length;
+ 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';
+ }
+ } else
+ /* Copy the string and its terminating NUL character. */
+ memcpy(dest, src, src_length + 1);
+ return src_length;
}
#endif /* HAVE_STRLCPY */