strstr.c 770 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. libc_hidden_proto(strstr)
  12. # define Wstrstr strstr
  13. #endif
  14. /* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
  15. Wchar *Wstrstr(const Wchar *s1, const Wchar *s2)
  16. {
  17. register const Wchar *s = s1;
  18. register const Wchar *p = s2;
  19. do {
  20. if (!*p) {
  21. return (Wchar *) s1;;
  22. }
  23. if (*p == *s) {
  24. ++p;
  25. ++s;
  26. } else {
  27. p = s2;
  28. if (!*s) {
  29. return NULL;
  30. }
  31. s = ++s1;
  32. }
  33. } while (1);
  34. }
  35. #ifndef WANT_WIDE
  36. libc_hidden_def(strstr)
  37. #else
  38. strong_alias(wcsstr,wcswcs)
  39. #endif