This patch adds optional support for strndup.

Signed-off-by: Grant Erickson <[email protected]>
---
 include/linux/string.h |    3 +++
 lib/string.c           |   21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/include/linux/string.h b/include/linux/string.h
index 6239039..5668290 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -59,6 +59,9 @@ extern __kernel_size_t strnlen(const char *,__kernel_size_t);
 #ifndef __HAVE_ARCH_STRDUP
 extern char * strdup(const char *);
 #endif
+#ifndef __HAVE_ARCH_STRNDUP
+extern char * strndup(const char *,__kernel_size_t);
+#endif
 #ifndef __HAVE_ARCH_STRSWAB
 extern char * strswab(const char *);
 #endif
diff --git a/lib/string.c b/lib/string.c
index 2c4f0ec..5fb6693 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -260,6 +260,27 @@ char * strdup(const char *s)
 }
 #endif
 
+#ifndef __HAVE_ARCH_STRNDUP
+char * strndup(const char *s, size_t n)
+{
+       size_t len;
+       char *new;
+
+       len = strnlen(s, n);
+
+       if ((s == NULL) ||
+               ((new = malloc (len + 1)) == NULL) ) {
+               return NULL;
+       }
+
+       strncpy (new, s, len);
+
+       new[len] = '\0';
+
+       return new;
+}
+#endif
+
 #ifndef __HAVE_ARCH_STRSPN
 /**
  * strspn - Calculate the length of the initial substring of @s which only
-- 
1.7.7.3

_______________________________________________
U-Boot mailing list
[email protected]
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to