summaryrefslogtreecommitdiff
path: root/include/lib/ArduinoJson/Polyfills/safe_strcmp.hpp
blob: 9baee5aa8d31ea5327bb488f161007c8166d4d75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License

#pragma once

#include "lib/ArduinoJson/Namespace.hpp"

#include <stdint.h>  // int8_t

namespace ARDUINOJSON_NAMESPACE {

inline int safe_strcmp(const char* a, const char* b) {
  if (a == b)
    return 0;
  if (!a)
    return -1;
  if (!b)
    return 1;
  return strcmp(a, b);
}

inline int safe_strncmp(const char* a, const char* b, size_t n) {
  if (a == b)
    return 0;
  if (!a)
    return -1;
  if (!b)
    return 1;
  return strncmp(a, b, n);
}
}  // namespace ARDUINOJSON_NAMESPACE