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