svn commit: trunk/uClibc/libc/string

pkj at uclibc.org pkj at uclibc.org
Thu Oct 19 10:17:13 UTC 2006


Author: pkj
Date: 2006-10-19 03:17:12 -0700 (Thu, 19 Oct 2006)
New Revision: 16402

Log:
Make strdup() use memcpy() rather than strcpy() to duplicate the string.  
The rationale is that we already have the length of the string to 
duplicate (from doing the malloc()), and memcpy() should then always be 
faster than strcpy() (or at least as fast).


Modified:
   trunk/uClibc/libc/string/strdup.c


Changeset:
Modified: trunk/uClibc/libc/string/strdup.c
===================================================================
--- trunk/uClibc/libc/string/strdup.c	2006-10-17 20:11:47 UTC (rev 16401)
+++ trunk/uClibc/libc/string/strdup.c	2006-10-19 10:17:12 UTC (rev 16402)
@@ -10,25 +10,23 @@
 
 #ifdef WANT_WIDE
 libc_hidden_proto(wcslen)
-libc_hidden_proto(wcscpy)
 # define Wstrdup wcsdup
 # define Wstrlen wcslen
-# define Wstrcpy wcscpy
 #else
 libc_hidden_proto(strdup)
 libc_hidden_proto(strlen)
-libc_hidden_proto(strcpy)
 # define Wstrdup strdup
 # define Wstrlen strlen
-# define Wstrcpy strcpy
 #endif
+libc_hidden_proto(memcpy)
 
 Wchar *Wstrdup(register const Wchar *s1)
 {
 	register Wchar *s;
+	register size_t l = (Wstrlen(s1) + 1) * sizeof(Wchar);
 
-    if ((s = malloc((Wstrlen(s1) + 1) * sizeof(Wchar))) != NULL) {
-		Wstrcpy(s, s1);
+	if ((s = malloc(l)) != NULL) {
+		memcpy(s, s1, l);
 	}
 
 	return s;




More information about the uClibc-cvs mailing list