The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | #include <stdio.h> |
David 'Digit' Turner | a8d1afb | 2011-01-06 08:39:44 +0100 | [diff] [blame] | 2 | #include <stdlib.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 3 | |
| 4 | #include <cutils/properties.h> |
| 5 | |
David 'Digit' Turner | a8d1afb | 2011-01-06 08:39:44 +0100 | [diff] [blame] | 6 | #include "dynarray.h" |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 7 | |
David 'Digit' Turner | a8d1afb | 2011-01-06 08:39:44 +0100 | [diff] [blame] | 8 | static void record_prop(const char* key, const char* name, void* opaque) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 9 | { |
David 'Digit' Turner | a8d1afb | 2011-01-06 08:39:44 +0100 | [diff] [blame] | 10 | strlist_t* list = opaque; |
| 11 | char temp[PROP_VALUE_MAX + PROP_NAME_MAX + 16]; |
Brian Muramatsu | a95abdd | 2011-02-14 17:17:21 -0800 | [diff] [blame] | 12 | snprintf(temp, sizeof temp, "[%s]: [%s]", key, name); |
David 'Digit' Turner | a8d1afb | 2011-01-06 08:39:44 +0100 | [diff] [blame] | 13 | strlist_append_dup(list, temp); |
| 14 | } |
| 15 | |
| 16 | static 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 Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 31 | } |
| 32 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 33 | int getprop_main(int argc, char *argv[]) |
| 34 | { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 35 | if (argc == 1) { |
David 'Digit' Turner | a8d1afb | 2011-01-06 08:39:44 +0100 | [diff] [blame] | 36 | list_properties(); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 37 | } 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 | } |