strcasestr.c 853 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #include <ctype.h>
  9. char *strcasestr(const char *s1, const char *s2)
  10. {
  11. register const char *s = s1;
  12. register const char *p = s2;
  13. #if 1
  14. do {
  15. if (!*p) {
  16. return (char *) s1;
  17. }
  18. if ((*p == *s)
  19. || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s)))
  20. ) {
  21. ++p;
  22. ++s;
  23. } else {
  24. p = s2;
  25. if (!*s) {
  26. return NULL;
  27. }
  28. s = ++s1;
  29. }
  30. } while (1);
  31. #else
  32. while (*p && *s) {
  33. if ((*p == *s)
  34. || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s)))
  35. ) {
  36. ++p;
  37. ++s;
  38. } else {
  39. p = s2;
  40. s = ++s1;
  41. }
  42. }
  43. return (*p) ? NULL : (char *) s1;
  44. #endif
  45. }
  46. libc_hidden_def(strcasestr)