Minh Nguyen / ArduinoJson
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers safe_strcmp.hpp Source File

safe_strcmp.hpp

00001 // ArduinoJson - arduinojson.org
00002 // Copyright Benoit Blanchon 2014-2021
00003 // MIT License
00004 
00005 #pragma once
00006 
00007 #include <ArduinoJson/Namespace.hpp>
00008 
00009 #include <stdint.h>  // int8_t
00010 
00011 namespace ARDUINOJSON_NAMESPACE {
00012 
00013 inline int safe_strcmp(const char* a, const char* b) {
00014   if (a == b)
00015     return 0;
00016   if (!a)
00017     return -1;
00018   if (!b)
00019     return 1;
00020   return strcmp(a, b);
00021 }
00022 
00023 inline int safe_strncmp(const char* a, const char* b, size_t n) {
00024   if (a == b)
00025     return 0;
00026   if (!a)
00027     return -1;
00028   if (!b)
00029     return 1;
00030   return strncmp(a, b, n);
00031 }
00032 }  // namespace ARDUINOJSON_NAMESPACE