parse_integer_property(device *current, const char *property_name, const char *property_value) { int nr_entries; unsigned_cell words[1024]; /* integer or integer array? */ nr_entries = 0; while (1) { char *end; words[nr_entries] = strtoul(property_value, &end, 0); if (property_value == end) break; nr_entries += 1; if (nr_entries * sizeof(words[0]) >= sizeof(words)) device_error(current, "buffer overflow"); property_value = end; } if (nr_entries == 0) device_error(current, "error parsing integer property %s (%s)", property_name, property_value); else if (nr_entries == 1) device_add_integer_property(current, property_name, words[0]); else { int i; for (i = 0; i < nr_entries; i++) { H2BE(words[i]); } /* perhaps integer array property is better */ device_add_array_property(current, property_name, words, sizeof(words[0]) * nr_entries); } }
void hw_add_integer_property (struct hw *me, const char *property, signed_cell integer) { H2BE (integer); hw_add_property (me, property, integer_property, &integer, sizeof(integer), &integer, sizeof(integer), NULL, permenant_object); }