| 345 | } |
| 346 | |
| 347 | int set_option_from_string(const struct nvram_accessor *nvram, struct cb_cmos_option_table *option_table, const char *value, const char *name) |
| 348 | { |
| 349 | void *raw; |
| 350 | struct cb_cmos_entries *cmos_entry = lookup_cmos_entry(option_table, name); |
| 351 | if (!cmos_entry) |
| 352 | return 1; |
| 353 | |
| 354 | struct cb_cmos_enums *cmos_enum; |
| 355 | switch (cmos_entry->config) { |
| 356 | case 'h': |
| 357 | /* only works on little endian */ |
| 358 | raw = malloc(sizeof(u64)); |
| 359 | *(u64*)raw = strtoull(value, NULL, 0); |
| 360 | break; |
| 361 | case 's': |
| 362 | raw = malloc(cmos_entry->length); |
| 363 | if (!raw) |
| 364 | return 1; |
| 365 | memset(raw, 0x00, cmos_entry->length); |
| 366 | strncpy(raw, value, cmos_entry->length); |
| 367 | break; |
| 368 | case 'e': |
| 369 | cmos_enum = lookup_cmos_enum_by_label(option_table, cmos_entry->config_id, value); |
| 370 | raw = malloc(sizeof(u32)); |
| 371 | *(u32*)raw = cmos_enum->value; |
| 372 | break; |
| 373 | default: /* fail */ |
| 374 | return 1; |
| 375 | } |
| 376 | |
| 377 | int ret = set_option_with(nvram, option_table, raw, name); |
| 378 | free(raw); |
| 379 | return ret; |
| 380 | } |
no test coverage detected