strncasecmp.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * strncasecmp for uClibc
  3. * Copyright (C) 2002 by Brian Stafford <brian@stafford.uklinux.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU Library General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  13. * for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this program; if not, write to the Free Software Foundation,
  17. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <string.h>
  20. #include <ctype.h>
  21. int strncasecmp (const char *a, const char *b, size_t len)
  22. {
  23. register int n;
  24. if (len < 1)
  25. return 0;
  26. while (*a == *b || (n = tolower (*a) - tolower (*b)) == 0)
  27. {
  28. if (*a == '\0' || --len < 1)
  29. return 0;
  30. a++, b++;
  31. }
  32. return n;
  33. }