summaryrefslogtreecommitdiffstats
path: root/toolbox/getprop.c
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2011-01-06 08:39:44 +0100
committerDavid 'Digit' Turner <digit@google.com>2011-01-08 12:22:08 +0100
commita8d1afb3e91b043fcd303a40ca4ac9293bbd2781 (patch)
tree85dfe1d89b0f078ccdf9610d169891cd5afd62f7 /toolbox/getprop.c
parent6b8caf0bb05c23da6f4d7ca1a23c98e6ca3c819a (diff)
downloadsystem_core-a8d1afb3e91b043fcd303a40ca4ac9293bbd2781.zip
system_core-a8d1afb3e91b043fcd303a40ca4ac9293bbd2781.tar.gz
system_core-a8d1afb3e91b043fcd303a40ca4ac9293bbd2781.tar.bz2
toolbox: make getprop print a sorted list of properties
This patch also factors out the dynarray_t/strlist_t code from ls.c and moves it to dynarray.[hc]. Change-Id: Ifae2b364d7c2733aad5551ad3c78ae72f8ac31f4
Diffstat (limited to 'toolbox/getprop.c')
-rw-r--r--toolbox/getprop.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/toolbox/getprop.c b/toolbox/getprop.c
index fc80a4d..616644a 100644
--- a/toolbox/getprop.c
+++ b/toolbox/getprop.c
@@ -1,13 +1,34 @@
#include <stdio.h>
+#include <stdlib.h>
#include <cutils/properties.h>
#include <sys/system_properties.h>
+#include "dynarray.h"
-static void proplist(const char *key, const char *name,
- void *user __attribute__((unused)))
+static void record_prop(const char* key, const char* name, void* opaque)
{
- printf("[%s]: [%s]\n", key, name);
+ strlist_t* list = opaque;
+ char temp[PROP_VALUE_MAX + PROP_NAME_MAX + 16];
+ snprintf(temp, sizeof temp, "[%s] [%s]", key, name);
+ strlist_append_dup(list, temp);
+}
+
+static void list_properties(void)
+{
+ strlist_t list[1] = { STRLIST_INITIALIZER };
+
+ /* Record properties in the string list */
+ (void)property_list(record_prop, list);
+
+ /* Sort everything */
+ strlist_sort(list);
+
+ /* print everything */
+ STRLIST_FOREACH(list, str, printf("%s\n", str));
+
+ /* voila */
+ strlist_done(list);
}
int __system_property_wait(prop_info *pi);
@@ -17,7 +38,7 @@ int getprop_main(int argc, char *argv[])
int n = 0;
if (argc == 1) {
- (void)property_list(proplist, NULL);
+ list_properties();
} else {
char value[PROPERTY_VALUE_MAX];
char *default_value;