]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
lib: string: move strlcpy() to a common place
authorMasahiro Yamada <yamada.m@jp.panasonic.com>
Thu, 20 Nov 2014 12:20:32 +0000 (21:20 +0900)
committerSimon Glass <sjg@chromium.org>
Thu, 11 Dec 2014 20:18:41 +0000 (13:18 -0700)
Move strlcpy() definition from drivers/usb/gadget/ether.c to
lib/string.c because it is a very useful function.
Let's add the prototype to include/linux/string.h too.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Simon Glass <sjg@chromium.org>
drivers/usb/gadget/ether.c
include/linux/string.h
lib/string.c

index d0dd29ffb25d9493efd0dc1a3eb96248c0a66f5e..ba442d5ed529bb04a88a41e630477b4a46b32d46 100644 (file)
@@ -852,30 +852,6 @@ DEFINE_CACHE_ALIGN_BUFFER(u8, control_req, USB_BUFSIZ);
 DEFINE_CACHE_ALIGN_BUFFER(u8, status_req, STATUS_BYTECOUNT);
 #endif
 
-
-/**
- * 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;
-}
-
 /*============================================================================*/
 
 /*
index 96348d617fca34c4abfbf00759a84b8178d8aae9..c7047ba0bca6a8bd191013eae45aea7307b71552 100644 (file)
@@ -30,6 +30,9 @@ extern char * strcpy(char *,const char *);
 #ifndef __HAVE_ARCH_STRNCPY
 extern char * strncpy(char *,const char *, __kernel_size_t);
 #endif
+#ifndef __HAVE_ARCH_STRLCPY
+size_t strlcpy(char *, const char *, size_t);
+#endif
 #ifndef __HAVE_ARCH_STRCAT
 extern char * strcat(char *, const char *);
 #endif
index 29c2ca7ef6b12688ccfec0c4ec8451ad47f49e1f..87c9a408e625de435c1051ccfaa20074dca0ad15 100644 (file)
@@ -102,6 +102,31 @@ char * strncpy(char * dest,const char *src,size_t count)
 }
 #endif
 
+#ifndef __HAVE_ARCH_STRLCPY
+/**
+ * strlcpy - Copy a C-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;
+}
+#endif
+
 #ifndef __HAVE_ARCH_STRCAT
 /**
  * strcat - Append one %NUL-terminated string to another