weird_strcmp.hpp 687 B

1234567891011121314151617181920212223242526272829
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2022, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson/Namespace.hpp>
  5. #include <string.h> // strcmp, strncmp
  6. // Issue #1198: strcmp() implementation that returns a value larger than 8-bit
  7. namespace ARDUINOJSON_NAMESPACE {
  8. int strcmp(const char* a, const char* b) {
  9. int result = ::strcmp(a, b);
  10. if (result > 0)
  11. return 2147483647;
  12. if (result < 0)
  13. return -214748364;
  14. return 0;
  15. }
  16. int strncmp(const char* a, const char* b, size_t n) {
  17. int result = ::strncmp(a, b, n);
  18. if (result > 0)
  19. return 2147483647;
  20. if (result < 0)
  21. return -214748364;
  22. return 0;
  23. }
  24. } // namespace ARDUINOJSON_NAMESPACE