env: net: U_BOOT_ENV_CALLBACKs should not depend on CMD_NET
[oweals/u-boot.git] / lib / string.c
index c4ca944bb42c0cabcea15a3cce3aca4f6fbf9029..9b779ddc3bbe42b6df36a70c3ece2213b40e5fa6 100644 (file)
@@ -15,6 +15,7 @@
  *    reentrant and should be faster). Use only strsep() in new code, please.
  */
 
+#include <config.h>
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/ctype.h>
@@ -325,6 +326,29 @@ char * strdup(const char *s)
 }
 #endif
 
+char * strndup(const char *s, size_t n)
+{
+       size_t len;
+       char *new;
+
+       if (s == NULL)
+               return NULL;
+
+       len = strlen(s);
+
+       if (n < len)
+               len = n;
+
+       new = malloc(len + 1);
+       if (new == NULL)
+               return NULL;
+
+       strncpy(new, s, len);
+       new[len] = '\0';
+
+       return new;
+}
+
 #ifndef __HAVE_ARCH_STRSPN
 /**
  * strspn - Calculate the length of the initial substring of @s which only