summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2010-08-04 03:43:54 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-08-06 19:09:38 +0200
commite0953c5db2cb2ac73ca4ffe2f91ee78939de4ede (patch)
treeff3aa9c2a9000162464c11d96f08cdbe41a183ce /lib
parent873910050ea0efc92db49ed233e70df7276a3f5b (diff)
downloadbarebox-e0953c5db2cb2ac73ca4ffe2f91ee78939de4ede.tar.gz
barebox-e0953c5db2cb2ac73ca4ffe2f91ee78939de4ede.tar.xz
string: add strlcpy support
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Cc: Andrea GALLO <andrea.gallo@stericsson.com> Cc: Gael SALLES <gael.salles@stericsson.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/string.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c
index cbb13d3287..77435aad79 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -62,6 +62,32 @@ char * strncpy(char * dest,const char *src,size_t count)
#endif
EXPORT_SYMBOL(strncpy);
+#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