strncasecmp.c 465 B

123456789101112131415161718
  1. #include <strings.h>
  2. #include <ctype.h>
  3. #include "libc.h"
  4. int strncasecmp(const char *_l, const char *_r, size_t n)
  5. {
  6. const unsigned char *l=(void *)_l, *r=(void *)_r;
  7. if (!n--) return 0;
  8. for (; *l && *r && n && (*l == *r || tolower(*l) == tolower(*r)); l++, r++, n--);
  9. return tolower(*l) - tolower(*r);
  10. }
  11. int __strncasecmp_l(const char *l, const char *r, size_t n, locale_t loc)
  12. {
  13. return strncasecmp(l, r, n);
  14. }
  15. weak_alias(__strncasecmp_l, strncasecmp_l);