OSDN Git Service

Write a new strxfrm that doesn't make function calls. Uses the same logic as
authorEric Andersen <andersen@codepoet.org>
Wed, 12 Jun 2002 21:47:35 +0000 (21:47 -0000)
committerEric Andersen <andersen@codepoet.org>
Wed, 12 Jun 2002 21:47:35 +0000 (21:47 -0000)
before but unrolls the func calls and thereby eliminates some steps and some
bytes.  Now adds just 40 bytes to .text.
 -Erik

libc/string/Makefile
libc/string/strxfrm.c [new file with mode: 0644]

index 0d034d1..2b8f39f 100644 (file)
@@ -31,20 +31,13 @@ MOBJW=  basename.o bcopy.o bzero.o dirname.o ffs.o memccpy.o memchr.o memcmp.o \
        strcmp.o strcpy.o strcspn.o strdup.o strlen.o strncasecmp.o strncat.o \
        strncmp.o strncpy.o strndup.o strnlen.o strpbrk.o strrchr.o strsep.o \
        strspn.o strstr.o strtok.o strtok_r.o \
-        __xpg_basename.o # strcoll.o strerror.o strxfrm.o 
+        __xpg_basename.o # strcoll.o strerror.o
 
 MOBJW2= wcscasecmp.o wcscat.o wcschrnul.o wcschr.o wcscmp.o wcscpy.o wcscspn.o \
        wcsdup.o wcslen.o wcsncasecmp.o wcsncat.o wcsncmp.o wcsncpy.o \
        wcsnlen.o wcspbrk.o wcsrchr.o wcsspn.o wcsstr.o wcstok.o wmemchr.o \
        wmemcmp.o wmemcpy.o wmemmove.o wmempcpy.o wmemset.o
 
-MSRC=string.c
-# MOBJ=strlen.o strcat.o strcpy.o strchr.o strcmp.o strncat.o strncpy.o \
-#      strncmp.o strrchr.o strdup.o strndup.o memcpy.o memccpy.o memset.o \
-#      memmove.o memcmp.o memchr.o ffs.o strnlen.o strxfrm.o stpcpy.o \
-#      stpncpy.o memrchr.o mempcpy.o
-MOBJ=strxfrm.o
-
 # ifeq ($(HAS_LOCALE),true)
 #      MOBJ += strcoll.o
 # endif
@@ -59,7 +52,7 @@ MOBJ2=
 # CSRC=strpbrk.c strsep.c strtok.c strtok_r.c strcspn.c \
 #      strspn.c strcasecmp.c strncasecmp.c strerror.c bcopy.c bzero.c \
 #      bcmp.c sys_errlist.c dirname.c basename.c
-CSRC=strerror.c sys_errlist.c
+CSRC=strerror.c sys_errlist.c strxfrm.c
 COBJS=$(patsubst %.c,%.o, $(CSRC))
 OBJS=$(MOBJ) $(MOBJ1) $(MOBJ2) $(COBJS) $(MOBJW)
 
diff --git a/libc/string/strxfrm.c b/libc/string/strxfrm.c
new file mode 100644 (file)
index 0000000..5acb824
--- /dev/null
@@ -0,0 +1,47 @@
+/* vi: set sw=4 ts=4: */
+/* strxfrm for uClibc
+ *
+ * Copyright (C) 2002 by Erik Andersen <andersen@uclibc.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+
+size_t strxfrm(char *dst, const char *src, size_t len)
+{
+       size_t length;
+       register char *ptr1, *ptr2;
+
+       length = len;
+       ptr1 = (char *) dst;
+       ptr2 = (char *) src;
+       while (length--) {
+               if (*ptr2)
+                       *ptr1++ = *ptr2++;
+               else
+                       *ptr1++ = '\0';
+       }
+       /* The first while loop should have done much of the heavy
+        * lifting for us.  This second look will finish the job if 
+        * that is necessary */
+       while (*ptr2)
+               ptr2++;
+       length = (ptr2 - src);
+
+       if (length<len)
+               return(length);
+       return(len);
+}