1 /*
2  *  Copyright (C) 1991, 1992  Linus Torvalds
3  */
4 
5 #include <xen/string.h>
6 
7 /**
8  * strlcpy - Copy 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). It does not pad
16  * out the result like strncpy() does.
17  */
strlcpy(char * dest,const char * src,size_t size)18 size_t strlcpy(char *dest, const char *src, size_t size)
19 {
20 	size_t ret = strlen(src);
21 
22 	if (size) {
23 		size_t len = (ret >= size) ? size-1 : ret;
24 		memcpy(dest, src, len);
25 		dest[len] = '\0';
26 	}
27 	return ret;
28 }
29 
30 /*
31  * Local variables:
32  * mode: C
33  * c-file-style: "BSD"
34  * c-basic-offset: 8
35  * tab-width: 8
36  * indent-tabs-mode: t
37  * End:
38  */
39