blob: 8d883eb14d9b5d55aee2ce44fae8f3351d690d51 [file] [log] [blame]
Roman Stratiienkod518a052021-02-25 19:15:14 +02001#ifndef UTILS_PROPERTIES_H_
2#define UTILS_PROPERTIES_H_
3
4#ifdef ANDROID
5
6#include <cutils/properties.h>
7
8#else
9
10#include <cstdio>
11#include <cstdlib>
12#include <cstring>
13
14// NOLINTNEXTLINE(readability-identifier-naming)
15constexpr int PROPERTY_VALUE_MAX = 92;
16
Roman Stratiienko5532b922021-03-04 15:22:09 +020017// NOLINTNEXTLINE(readability-identifier-naming)
Roman Stratiienkod518a052021-02-25 19:15:14 +020018auto inline property_get(const char *name, char *value,
19 const char *default_value) -> int {
20 char *prop = std::getenv(name);
21 if (prop == nullptr) {
22 snprintf(value, PROPERTY_VALUE_MAX, "%s", default_value);
23 }
Roman Stratiienkod26619b2021-08-04 19:55:37 +030024 return static_cast<int>(strlen(value));
Roman Stratiienkod518a052021-02-25 19:15:14 +020025}
26
27#endif
28
29#endif