strstr.c 776 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (C) 2002 Manuel Novoa III
  3. * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include "_string.h"
  8. #ifdef WANT_WIDE
  9. # define Wstrstr wcsstr
  10. #else
  11. # define Wstrstr strstr
  12. #endif
  13. /* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
  14. Wchar *Wstrstr(const Wchar *s1, const Wchar *s2)
  15. {
  16. register const Wchar *s = s1;
  17. register const Wchar *p = s2;
  18. do {
  19. if (!*p) {
  20. return (Wchar *) s1;;
  21. }
  22. if (*p == *s) {
  23. ++p;
  24. ++s;
  25. } else {
  26. p = s2;
  27. if (!*s) {
  28. return NULL;
  29. }
  30. s = ++s1;
  31. }
  32. } while (1);
  33. }
  34. #ifndef WANT_WIDE
  35. libc_hidden_def(strstr)
  36. #elif defined __UCLIBC_SUSV3_LEGACY__
  37. strong_alias(wcsstr,wcswcs)
  38. #endif