mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
lib: move strlcat()
Allow the function to be individually linkable, discardable, and overridable. Signed-off-by: Jan Beulich <jbeulich@suse.com> Acked-by: Julien Grall <jgrall@amazon.com>
This commit is contained in:
1 parent
ead845c4fb
commit
9c1e40fb7f
3 files changed
+42
-29
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 1991, 1992 Linus Torvalds
|
||||
*/
|
||||
|
||||
#include <xen/string.h>
|
||||
|
||||
/**
|
||||
* 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:
|
||||
*/
|
||||