Home | History | Annotate | Download | only in toolbox
      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 #include <cutils/properties.h>
      5 
      6 #include "dynarray.h"
      7 
      8 static void record_prop(const char* key, const char* name, void* opaque)
      9 {
     10     strlist_t* list = opaque;
     11     char temp[PROP_VALUE_MAX + PROP_NAME_MAX + 16];
     12     snprintf(temp, sizeof temp, "[%s]: [%s]", key, name);
     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);
     31 }
     32 
     33 int getprop_main(int argc, char *argv[])
     34 {
     35     if (argc == 1) {
     36         list_properties();
     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 }
     51