strcasestr.c 934 B

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