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