blob: c8ddbae15095508484f9c3ca7b5fbf3f01a41dbc [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);
Roman Stratiienko0a90b272021-08-04 22:43:06 +030021 snprintf(value, PROPERTY_VALUE_MAX, "%s",
22 (prop == nullptr) ? default_value : prop);
Roman Stratiienkod26619b2021-08-04 19:55:37 +030023 return static_cast<int>(strlen(value));
Roman Stratiienkod518a052021-02-25 19:15:14 +020024}
25
26#endif
27
28#endif