strcasestr.c 854 B

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