blob: dcc0ea0305d37a381be373f70a6972038291a94a [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001#include <stdio.h>
David 'Digit' Turnera8d1afb2011-01-06 08:39:44 +01002#include <stdlib.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08003
4#include <cutils/properties.h>
5
David 'Digit' Turnera8d1afb2011-01-06 08:39:44 +01006#include "dynarray.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08007
David 'Digit' Turnera8d1afb2011-01-06 08:39:44 +01008static void record_prop(const char* key, const char* name, void* opaque)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08009{
David 'Digit' Turnera8d1afb2011-01-06 08:39:44 +010010 strlist_t* list = opaque;
11 char temp[PROP_VALUE_MAX + PROP_NAME_MAX + 16];
Brian Muramatsua95abdd2011-02-14 17:17:21 -080012 snprintf(temp, sizeof temp, "[%s]: [%s]", key, name);
David 'Digit' Turnera8d1afb2011-01-06 08:39:44 +010013 strlist_append_dup(list, temp);
14}
15
16static void list_properties(void)
17{
18 strlist_t list[1] = { STRLIST_INITIALIZER };
19
20 /* Record properties in the string list */
21 (void)property_list(record_prop, list);
22
23 /* Sort everything */
24 strlist_sort(list);
25
26 /* print everything */
27 STRLIST_FOREACH(list, str, printf("%s\n", str));
28
29 /* voila */
30 strlist_done(list);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080031}
32
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080033int getprop_main(int argc, char *argv[])
34{
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080035 if (argc == 1) {
David 'Digit' Turnera8d1afb2011-01-06 08:39:44 +010036 list_properties();
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080037 } else {
38 char value[PROPERTY_VALUE_MAX];
39 char *default_value;
40 if(argc > 2) {
41 default_value = argv[2];
42 } else {
43 default_value = "";
44 }
45
46 property_get(argv[1], value, default_value);
47 printf("%s\n", value);
48 }
49 return 0;
50}