From 4eacd70f85ec2ffc071d06945524c40967ce30f7 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 26 Jan 2017 17:31:40 -0800 Subject: [PATCH] Support arbitrary-length properties in property_list. Bug: http://b/33926793 Test: visual inspection Change-Id: Ida84c3aaafa5411a9886f8d3d45679fd60ddc00d --- libcutils/Android.bp | 2 +- libcutils/{properties.c => properties.cpp} | 28 ++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) rename libcutils/{properties.c => properties.cpp} (86%) diff --git a/libcutils/Android.bp b/libcutils/Android.bp index b96e3ae24..1cec781d6 100644 --- a/libcutils/Android.bp +++ b/libcutils/Android.bp @@ -80,7 +80,7 @@ cc_library { "ashmem-dev.c", "klog.cpp", "partition_utils.c", - "properties.c", + "properties.cpp", "qtaguid.c", "trace-dev.c", "uevent.c", diff --git a/libcutils/properties.c b/libcutils/properties.cpp similarity index 86% rename from libcutils/properties.c rename to libcutils/properties.cpp index bdbddd023..43ad5748e 100644 --- a/libcutils/properties.c +++ b/libcutils/properties.cpp @@ -112,9 +112,7 @@ int property_set(const char *key, const char *value) { } int property_get(const char *key, char *value, const char *default_value) { - int len; - - len = __system_property_get(key, value); + int len = __system_property_get(key, value); if (len > 0) { return len; } @@ -126,21 +124,21 @@ int property_get(const char *key, char *value, const char *default_value) { return len; } -struct property_list_callback_data { - void (*propfn)(const char *key, const char *value, void *cookie); - void *cookie; +struct callback_data { + void (*callback)(const char* name, const char* value, void* cookie); + void* cookie; }; -static void property_list_callback(const prop_info *pi, void *cookie) { - char name[PROP_NAME_MAX]; - char value[PROP_VALUE_MAX]; - struct property_list_callback_data *data = cookie; - - __system_property_read(pi, name, value); - data->propfn(name, value, data->cookie); +static void trampoline(void* raw_data, const char* name, const char* value) { + callback_data* data = reinterpret_cast(raw_data); + data->callback(name, value, data->cookie); } -int property_list(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie) { - struct property_list_callback_data data = {propfn, cookie}; +static void property_list_callback(const prop_info* pi, void* data) { + __system_property_read_callback(pi, trampoline, data); +} + +int property_list(void (*fn)(const char* name, const char* value, void* cookie), void* cookie) { + callback_data data = { fn, cookie }; return __system_property_foreach(property_list_callback, &data); }