From: Jan Beulich Date: Thu, 22 Apr 2021 12:49:10 +0000 (+0200) Subject: lib: move strlcat() X-Git-Tag: archive/raspbian/4.16.0+51-g0941d6cb-1+rpi1~2^2~42^2~626 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=9c1e40fb7f9b197fa1c20842bc2fdb47550a2f33;p=xen.git lib: move strlcat() Allow the function to be individually linkable, discardable, and overridable. Signed-off-by: Jan Beulich Acked-by: Julien Grall --- diff --git a/xen/common/string.c b/xen/common/string.c index 84af23270d..6042262b49 100644 --- a/xen/common/string.c +++ b/xen/common/string.c @@ -56,35 +56,6 @@ int (strcasecmp)(const char *s1, const char *s2) } #endif -#ifndef __HAVE_ARCH_STRLCAT -/** - * strlcat - Append a %NUL terminated string into a sized buffer - * @dest: Where to copy the string to - * @src: Where to copy the string from - * @size: size of destination buffer - * - * Compatible with *BSD: the result is always a valid - * NUL-terminated string that fits in the buffer (unless, - * of course, the buffer size is zero). - */ -size_t strlcat(char *dest, const char *src, size_t size) -{ - size_t slen = strlen(src); - size_t dlen = strnlen(dest, size); - char *p = dest + dlen; - - while ((p - dest) < size) - if ((*p++ = *src++) == '\0') - break; - - if (dlen < size) - *(p-1) = '\0'; - - return slen + dlen; -} -EXPORT_SYMBOL(strlcat); -#endif - #ifndef __HAVE_ARCH_STRCHR /** * strchr - Find the first occurrence of a character in a string diff --git a/xen/lib/Makefile b/xen/lib/Makefile index ed1d2e47d4..0c6c726adf 100644 --- a/xen/lib/Makefile +++ b/xen/lib/Makefile @@ -15,6 +15,7 @@ lib-y += parse-size.o lib-y += rbtree.o lib-y += sort.o lib-y += strcmp.o +lib-y += strlcat.o lib-y += strlcpy.o lib-y += strlen.o lib-y += strncmp.o diff --git a/xen/lib/strlcat.c b/xen/lib/strlcat.c new file mode 100644 index 0000000000..ec32be4890 --- /dev/null +++ b/xen/lib/strlcat.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 1991, 1992 Linus Torvalds + */ + +#include + +/** + * strlcat - Append a %NUL terminated string into a sized buffer + * @dest: Where to copy the string to + * @src: Where to copy the string from + * @size: size of destination buffer + * + * Compatible with *BSD: the result is always a valid + * NUL-terminated string that fits in the buffer (unless, + * of course, the buffer size is zero). + */ +size_t strlcat(char *dest, const char *src, size_t size) +{ + size_t slen = strlen(src); + size_t dlen = strnlen(dest, size); + char *p = dest + dlen; + + while ((p - dest) < size) + if ((*p++ = *src++) == '\0') + break; + + if (dlen < size) + *(p-1) = '\0'; + + return slen + dlen; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 8 + * tab-width: 8 + * indent-tabs-mode: t + * End: + */