Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Feb 2010 19:02:09 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r203391 - head/lib/libc/string
Message-ID:  <201002021902.o12J29su049090@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002021902.o12J29su049090>