1
0

string_nocasecmp.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * string_nocasecmp.c
  3. */
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include "private.h"
  7. #include "lub/ctype.h"
  8. /*--------------------------------------------------------- */
  9. int lub_string_nocasecmp(const char *cs, const char *ct)
  10. {
  11. int result = 0;
  12. while ((0 == result) && *cs && *ct) {
  13. /*lint -e155 Ignoring { }'ed sequence within an expression, 0 assumed
  14. * MACRO implementation uses braces to prevent multiple increments
  15. * when called.
  16. */
  17. int s = lub_ctype_tolower(*cs++);
  18. int t = lub_ctype_tolower(*ct++);
  19. result = s - t;
  20. }
  21. /*lint -e774 Boolean within 'if' always evealuates to True
  22. * not the case because of tolower() evaluating to 0 under lint
  23. * (see above)
  24. */
  25. if (0 == result) {
  26. /* account for different string lengths */
  27. result = *cs - *ct;
  28. }
  29. return result;
  30. }
  31. /*--------------------------------------------------------- */
  32. char *lub_string_tolower(const char *str)
  33. {
  34. char *tmp = strdup(str);
  35. char *p = tmp;
  36. while (*p) {
  37. *p = tolower(*p);
  38. p++;
  39. }
  40. return tmp;
  41. }
  42. /*--------------------------------------------------------- */