Back to index

glibc  2.9
Functions
wcsstr.c File Reference
#include <wchar.h>

Go to the source code of this file.

Functions

wchar_t * wcsstr (wchar_t *haystack, const wchar_t *needle) const

Function Documentation

wchar_t* wcsstr ( wchar_t *  haystack,
const wchar_t *  needle 
) const

Definition at line 33 of file wcsstr.c.

{
  register wchar_t b, c;

  if ((b = *needle) != L'\0')
    {
      haystack--;                         /* possible ANSI violation */
      do
       if ((c = *++haystack) == L'\0')
         goto ret0;
      while (c != b);

      if (!(c = *++needle))
       goto foundneedle;
      ++needle;
      goto jin;

      for (;;)
       {
         register wchar_t a;
         register const wchar_t *rhaystack, *rneedle;

         do
           {
             if (!(a = *++haystack))
              goto ret0;
             if (a == b)
              break;
             if ((a = *++haystack) == L'\0')
              goto ret0;
shloop:             ;
           }
         while (a != b);

jin:     if (!(a = *++haystack))
           goto ret0;

         if (a != c)
           goto shloop;

         if (*(rhaystack = haystack-- + 1) == (a = *(rneedle = needle)))
           do
             {
              if (a == L'\0')
                goto foundneedle;
              if (*++rhaystack != (a = *++needle))
                break;
              if (a == L'\0')
                goto foundneedle;
             }
           while (*++rhaystack == (a = *++needle));

         needle = rneedle;           /* took the register-poor approach */

         if (a == L'\0')
           break;
       }
    }
foundneedle:
  return (wchar_t*) haystack;
ret0:
  return NULL;
}