Author: ed
Date: Tue Feb  2 19:02:08 2010
New Revision: 203391
URL: http://svn.freebsd.org/changeset/base/203391

Log:
  Implement strndup(3) using strnlen(3).
  
  This makes the implementation a bit more consistent with strdup(3),
  which uses strlen(3).

Modified:
  head/lib/libc/string/strndup.c

Modified: head/lib/libc/string/strndup.c
==============================================================================
--- head/lib/libc/string/strndup.c      Tue Feb  2 18:50:02 2010        
(r203390)
+++ head/lib/libc/string/strndup.c      Tue Feb  2 19:02:08 2010        
(r203391)
@@ -42,9 +42,7 @@ strndup(const char *str, size_t n)
        size_t len;
        char *copy;
 
-       for (len = 0; len < n && str[len]; len++)
-               continue;
-
+       len = strnlen(str, n);
        if ((copy = malloc(len + 1)) == NULL)
                return (NULL);
        memcpy(copy, str, len);
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to