strcasecmp.c 605 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * strcasecmp.c -- provides strcasecmp() and strncasecmp if necessary.
  3. *
  4. */
  5. #include "memcpy.h"
  6. #ifndef HAVE_STRCASECMP
  7. int strcasecmp(const char *s1, const char *s2)
  8. {
  9. while ((*s1) && (*s2) && (toupper(*s1) == toupper(*s2))) {
  10. s1++;
  11. s2++;
  12. }
  13. return toupper(*s1) - toupper(*s2);
  14. }
  15. #endif /* !HAVE_STRCASECMP */
  16. #ifndef HAVE_STRNCASECMP
  17. int strncasecmp(const char *s1, const char *s2, size_t n)
  18. {
  19. if (!n)
  20. return 0;
  21. while (--n && (*s1) && (*s2) && (toupper(*s1) == toupper(*s2))) {
  22. s1++;
  23. s2++;
  24. }
  25. return toupper(*s1) - toupper(*s2);
  26. }
  27. #endif /* !HAVE_STRNCASECMP */