[U-Boot] [PATCH v12 1/8] libc: move strlcpy() from ether.c to string.c
Kuo-Jung Su
dantesu at gmail.com
Tue Apr 1 10:46:52 CEST 2014
From: Kuo-Jung Su <dantesu at faraday-tech.com>
It would be better to have strlcpy() moved to lib/string.c,
so that it could be reused by others without enabling
USB Gadget Ethernet.
Signed-off-by: Kuo-Jung Su <dantesu at faraday-tech.com>
CC: Albert Aribaud <albert.u.boot at aribaud.net>
CC: Wolfgang Denk <wd at denx.de>
Cc: Marek Vasut <marex at denx.de>
---
Changes for v12:
- Initial commit
drivers/usb/gadget/ether.c | 24 ------------------------
include/linux/string.h | 3 +++
lib/string.c | 25 +++++++++++++++++++++++++
3 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index cc6cc1f..cabd81f 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -857,30 +857,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;
-}
-
/*============================================================================*/
/*
diff --git a/include/linux/string.h b/include/linux/string.h
index 8e44855..5c9d6c3 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -23,6 +23,9 @@ extern __kernel_size_t strspn(const char *,const char *);
#ifndef __HAVE_ARCH_STRCPY
extern char * strcpy(char *,const char *);
#endif
+#ifndef __HAVE_ARCH_STRLCPY
+extern __kernel_size_t strlcpy(char *, const char *, __kernel_size_t);
+#endif
#ifndef __HAVE_ARCH_STRNCPY
extern char * strncpy(char *,const char *, __kernel_size_t);
#endif
diff --git a/lib/string.c b/lib/string.c
index 29c2ca7..adf718c 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -80,6 +80,31 @@ char * strcpy(char * dest,const char *src)
}
#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;
+}
+#endif
+
#ifndef __HAVE_ARCH_STRNCPY
/**
* strncpy - Copy a length-limited, %NUL-terminated string
--
1.7.9.5
More information about the U-Boot
mailing list