diff options
author | Linus Torvalds <torvalds@home.transmeta.com> | 2003-05-24 20:42:34 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@home.transmeta.com> | 2003-05-24 20:42:34 -0700 |
commit | 0297761dda3adaf03839f95e7b022d42f4d7f7d2 (patch) | |
tree | bf8ec8bd2cce76a514e6f51bde703c09c78ca8b3 /lib | |
parent | b9fdbdca514c68074647a47222e144d66783bb7e (diff) | |
download | history-0297761dda3adaf03839f95e7b022d42f4d7f7d2.tar.gz |
Add 'strlcpy()' implementation
Diffstat (limited to 'lib')
-rw-r--r-- | lib/string.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c index c4b66913d22878..b19212bc5d0073 100644 --- a/lib/string.c +++ b/lib/string.c @@ -22,6 +22,7 @@ #include <linux/types.h> #include <linux/string.h> #include <linux/ctype.h> +#include <linux/module.h> #ifndef __HAVE_ARCH_STRNICMP /** @@ -94,6 +95,32 @@ char * strncpy(char * dest,const char *src,size_t count) } #endif +#ifndef __HAVE_ARCH_STRLCPY +/** + * strlcpy - Copy 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). It does not pad + * out the result like strncpy() does. + */ +size_t strlcpy(char *dest, const char *src, size_t size) +{ + size_t ret = strlen(src); + + if (size) { + size_t len = (ret >= size) ? size-1 : ret; + memcpy(dest, src, len); + dest[len] = '\0'; + } + return ret; +} +EXPORT_SYMBOL(strlcpy); +#endif + #ifndef __HAVE_ARCH_STRCAT /** * strcat - Append one %NUL-terminated string to another |