summaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
authorChristopher R. Palmer <crpalmer@gmail.com>2016-03-12 06:08:16 -0500
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-03-12 12:41:00 -0800
commita41177ed09db230c5491f23f97a37668b94a9b7c (patch)
tree6ec66f3b688ce5df26ded87588b269b5e9c726d1 /init
parent36060ddbd0fa003c808218fa62afbcb65a5f0878 (diff)
downloadsystem_core-a41177ed09db230c5491f23f97a37668b94a9b7c.zip
system_core-a41177ed09db230c5491f23f97a37668b94a9b7c.tar.gz
system_core-a41177ed09db230c5491f23f97a37668b94a9b7c.tar.bz2
init: Add property_get_bool
Change-Id: I2bef1862f6126f79c64faa7080a00096e4f955c5
Diffstat (limited to 'init')
-rw-r--r--init/property_service.cpp27
-rw-r--r--init/property_service.h1
2 files changed, 28 insertions, 0 deletions
diff --git a/init/property_service.cpp b/init/property_service.cpp
index 11ff06b..fe82bef 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -150,6 +150,33 @@ int __property_get(const char *name, char *value)
return __system_property_get(name, value);
}
+bool property_get_bool(const char *key, bool default_value) {
+ if (!key) {
+ return default_value;
+ }
+
+ bool result = default_value;
+ char buf[PROP_VALUE_MAX] = {'\0',};
+
+ int len = __property_get(key, buf);
+ if (len == 1) {
+ char ch = buf[0];
+ if (ch == '0' || ch == 'n') {
+ result = false;
+ } else if (ch == '1' || ch == 'y') {
+ result = true;
+ }
+ } else if (len > 1) {
+ if (!strcmp(buf, "no") || !strcmp(buf, "false") || !strcmp(buf, "off")) {
+ result = false;
+ } else if (!strcmp(buf, "yes") || !strcmp(buf, "true") || !strcmp(buf, "on")) {
+ result = true;
+ }
+ }
+
+ return result;
+}
+
static void write_persistent_property(const char *name, const char *value)
{
char tempPath[PATH_MAX];
diff --git a/init/property_service.h b/init/property_service.h
index 303f251..6b542b5 100644
--- a/init/property_service.h
+++ b/init/property_service.h
@@ -28,6 +28,7 @@ extern void start_property_service(void);
void get_property_workspace(int *fd, int *sz);
extern int __property_get(const char *name, char *value);
extern int property_set(const char *name, const char *value);
+extern bool property_get_bool(const char *name, bool def_value);
extern bool properties_initialized();
#ifndef __clang__