strstr.c 823 B

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