-remove async ecc key generation, not needed
[oweals/gnunet.git] / src / util / common_allocation.c
index 1828d826a5a24a4355f92b0b6dd528adc6219f83..dfa65d579dc6b74b0e566e44baff2fc5451dcaa1 100644 (file)
@@ -256,6 +256,21 @@ GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber)
 }
 
 
+#if ! HAVE_STRNLEN
+static size_t
+strnlen (const char *s, 
+        size_t n)
+{
+  const char *e;
+
+  e = memchr (s, '\0', n);
+  if (NULL == e)
+    return n;
+  return e - s;
+}
+#endif
+
+
 /**
  * Dup partially a string (same semantics as strndup).
  *
@@ -271,8 +286,10 @@ GNUNET_xstrndup_ (const char *str, size_t len, const char *filename,
 {
   char *res;
 
+  if (0 == len)
+    return GNUNET_strdup ("");
   GNUNET_assert_at (str != NULL, filename, linenumber);
-  len = GNUNET_MIN (len, strlen (str));
+  len = strnlen (str, len);
   res = GNUNET_xmalloc_ (len + 1, filename, linenumber);
   memcpy (res, str, len);
   /* res[len] = '\0'; 'malloc' zeros out anyway */