strcasestr.c 1.0 KB

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