We have a lot of kernel string functions already for use by common, driver and board code, but we are lacking strlcat. Add it to simplify porting code using it. Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- include/linux/string.h | 3 +++ lib/string.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index 0d046f783280..4aa11555a005 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -55,6 +55,9 @@ extern char * strcat(char *, const char *); #ifndef __HAVE_ARCH_STRNCAT extern char * strncat(char *, const char *, __kernel_size_t); #endif +#ifndef __HAVE_ARCH_STRLCAT +extern __kernel_size_t strlcat(char *dest, const char *src, __kernel_size_t count); +#endif #ifndef __HAVE_ARCH_STRCMP extern int strcmp(const char *,const char *); #endif diff --git a/lib/string.c b/lib/string.c index 50c2016c2bd8..cab543baf38d 100644 --- a/lib/string.c +++ b/lib/string.c @@ -270,6 +270,27 @@ char * strncat(char *dest, const char *src, size_t count) #endif EXPORT_SYMBOL(strncat); +#ifndef __HAVE_ARCH_STRLCAT +size_t strlcat(char *dest, const char *src, size_t count) +{ + size_t dsize = strlen(dest); + size_t len = strlen(src); + size_t res = dsize + len; + + /* This would be a bug */ + BUG_ON(dsize >= count); + + dest += dsize; + count -= dsize; + if (len >= count) + len = count-1; + __builtin_memcpy(dest, src, len); + dest[len] = 0; + return res; +} +EXPORT_SYMBOL(strlcat); +#endif + #ifndef __HAVE_ARCH_STRCMP /** * strcmp - Compare two strings -- 2.39.5