blob: c001fda72ac53121be2a0b30a74babf4a07150f6 [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
6#include <sys/system_properties.h>
David 'Digit' Turnera8d1afb2011-01-06 08:39:44 +01007#include "dynarray.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08008
David 'Digit' Turnera8d1afb2011-01-06 08:39:44 +01009static void record_prop(const char* key, const char* name, void* opaque)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080010{
David 'Digit' Turnera8d1afb2011-01-06 08:39:44 +010011 strlist_t* list = opaque;
12 char temp[PROP_VALUE_MAX + PROP_NAME_MAX + 16];
Brian Muramatsua95abdd2011-02-14 17:17:21 -080013 snprintf(temp, sizeof temp, "[%s]: [%s]", key, name);
David 'Digit' Turnera8d1afb2011-01-06 08:39:44 +010014 strlist_append_dup(list, temp);
15}
16
17static void list_properties(void)
18{
19 strlist_t list[1] = { STRLIST_INITIALIZER };
20
21 /* Record properties in the string list */
22 (void)property_list(record_prop, list);
23
24 /* Sort everything */
25 strlist_sort(list);
26
27 /* print everything */
28 STRLIST_FOREACH(list, str, printf("%s\n", str));
29
30 /* voila */
31 strlist_done(list);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080032}
33
34int __system_property_wait(prop_info *pi);
35
36int getprop_main(int argc, char *argv[])
37{
38 int n = 0;
39
40 if (argc == 1) {
David 'Digit' Turnera8d1afb2011-01-06 08:39:44 +010041 list_properties();
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080042 } else {
43 char value[PROPERTY_VALUE_MAX];
44 char *default_value;
45 if(argc > 2) {
46 default_value = argv[2];
47 } else {
48 default_value = "";
49 }
50
51 property_get(argv[1], value, default_value);
52 printf("%s\n", value);
53 }
54 return 0;
55}