1 /*
2  *  Copyright (C) 1991, 1992  Linus Torvalds
3  */
4 
5 #include <xen/string.h>
6 
7 /**
8  * strlcat - Append a %NUL terminated string into a sized buffer
9  * @dest: Where to copy the string to
10  * @src: Where to copy the string from
11  * @size: size of destination buffer
12  *
13  * Compatible with *BSD: the result is always a valid
14  * NUL-terminated string that fits in the buffer (unless,
15  * of course, the buffer size is zero).
16  */
strlcat(char * dest,const char * src,size_t size)17 size_t strlcat(char *dest, const char *src, size_t size)
18 {
19 	size_t slen = strlen(src);
20 	size_t dlen = strnlen(dest, size);
21 	char *p = dest + dlen;
22 
23 	while ((p - dest) < size)
24 		if ((*p++ = *src++) == '\0')
25 			break;
26 
27 	if (dlen < size)
28 		*(p-1) = '\0';
29 
30 	return slen + dlen;
31 }
32 
33 /*
34  * Local variables:
35  * mode: C
36  * c-file-style: "BSD"
37  * c-basic-offset: 8
38  * tab-width: 8
39  * indent-tabs-mode: t
40  * End:
41  */
42