Merge "Support arbitrary-length properties in property_list." am: c8121ba029 am: 92aab6dbd1 am: be34e5661d

am: d5df20a2f3

Change-Id: I73e01d65fd3df3ae9f64c47e2d4148d2c055fb82
This commit is contained in:
Elliott Hughes 2017-01-27 07:55:56 +00:00 committed by android-build-merger
commit 5881843c59
2 changed files with 14 additions and 16 deletions

View File

@ -98,7 +98,7 @@ cc_library {
"ashmem-dev.c",
"klog.cpp",
"partition_utils.c",
"properties.c",
"properties.cpp",
"qtaguid.c",
"trace-dev.c",
"uevent.c",

View File

@ -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<callback_data*>(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);
}