blob: 0b49c612454cb1957d57cfec67aa5adafd465c60 [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 {
Roman Stratiienko24a7fc42021-12-23 16:25:20 +020020 // NOLINTNEXTLINE (concurrency-mt-unsafe)
Roman Stratiienkod518a052021-02-25 19:15:14 +020021 char *prop = std::getenv(name);
Roman Stratiienko0a90b272021-08-04 22:43:06 +030022 snprintf(value, PROPERTY_VALUE_MAX, "%s",
23 (prop == nullptr) ? default_value : prop);
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