OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / string / strstr.c
index aafcaf9..685a2f8 100644 (file)
@@ -1,54 +1,44 @@
-/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
- * This file is part of the Linux-8086 C library and is distributed
- * under the GNU Library General Public License.
+/*
+ * Copyright (C) 2002     Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  */
 
-#include <string.h>
-
-#if 1
-/* We've now got a nice fast strchr and memcmp use them */
-
-char *
-strstr(s1, s2)
-char *s1; char *s2;
-{
-   register int l = strlen(s2);
-   register char * p = s1;
-
-   if( l==0 ) return p;
-
-   while (p = strchr(p, *s2))
-   {
-      if( memcmp(p, s2, l) == 0 )
-         return p;
-      p++;
-   }
-   return (char *) 0;
-}
+#include "_string.h"
 
+#ifdef WANT_WIDE
+# define Wstrstr wcsstr
 #else
-/* This is a nice simple self contained strstr,
-   now go and work out why the GNU one is faster :-) */
-
-char *strstr(str1, str2)
-char *str1, *str2;
-{
-    register char *Sptr, *Tptr;
-    int        len = strlen(str1) -strlen(str2) + 1;
-
-    if (*str2)
-       for (; len > 0; len--, str1++){
-           if (*str1 != *str2)
-               continue;
-
-           for (Sptr = str1, Tptr = str2; *Tptr != '\0'; Sptr++, Tptr++)
-               if (*Sptr != *Tptr)
-                   break;
+libc_hidden_proto(strstr)
+# define Wstrstr strstr
+#endif
 
-           if (*Tptr == '\0')
-               return (char*) str1;
-       }
+/* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
 
-    return (char*)0;
+Wchar *Wstrstr(const Wchar *s1, const Wchar *s2)
+{
+       register const Wchar *s = s1;
+       register const Wchar *p = s2;
+
+       do {
+               if (!*p) {
+                       return (Wchar *) s1;;
+               }
+               if (*p == *s) {
+                       ++p;
+                       ++s;
+               } else {
+                       p = s2;
+                       if (!*s) {
+                               return NULL;
+                       }
+                       s = ++s1;
+               }
+       } while (1);
 }
+#ifndef WANT_WIDE
+libc_hidden_def(strstr)
+#else
+strong_alias(wcsstr,wcswcs)
 #endif