* prepare_cmos_write * * The caller wishes to set a CMOS parameter represented by 'e' to a value * whose string representation is stored in 'value_str'. Perform sanity * checking on 'value_str'. On error, return an error code. Else store the * numeric equivalent of 'value_str' in '*value' and return OK. ****************************************************************************/
| 62 | * numeric equivalent of 'value_str' in '*value' and return OK. |
| 63 | ****************************************************************************/ |
| 64 | int prepare_cmos_write(const cmos_entry_t * e, const char value_str[], |
| 65 | unsigned long long *value) |
| 66 | { |
| 67 | const cmos_enum_t *q; |
| 68 | unsigned long long out; |
| 69 | const char *p; |
| 70 | char *memory = NULL; |
| 71 | int negative, result, found_one; |
| 72 | |
| 73 | if ((result = prepare_cmos_op_common(e)) != OK) |
| 74 | return result; |
| 75 | |
| 76 | switch (e->config) { |
| 77 | case CMOS_ENTRY_ENUM: |
| 78 | /* Make sure the user's input corresponds to a valid option. */ |
| 79 | for (q = first_cmos_enum_id(e->config_id), found_one = 0; |
| 80 | q != NULL; q = next_cmos_enum_id(q)) { |
| 81 | found_one = 1; |
| 82 | |
| 83 | if (!strncmp(q->text, value_str, CMOS_MAX_TEXT_LENGTH)) |
| 84 | break; |
| 85 | } |
| 86 | |
| 87 | if (!found_one) |
| 88 | return CMOS_OP_NO_MATCHING_ENUM; |
| 89 | |
| 90 | if (q == NULL) |
| 91 | return CMOS_OP_BAD_ENUM_VALUE; |
| 92 | |
| 93 | out = q->value; |
| 94 | break; |
| 95 | |
| 96 | case CMOS_ENTRY_HEX: |
| 97 | /* See if the first character of 'value_str' (excluding |
| 98 | * any initial whitespace) is a minus sign. |
| 99 | */ |
| 100 | for (p = value_str; isspace((int)(unsigned char)*p); p++) ; |
| 101 | negative = (*p == '-'); |
| 102 | |
| 103 | out = strtoull(value_str, (char **)&p, 0); |
| 104 | |
| 105 | if (*p) |
| 106 | return CMOS_OP_INVALID_INT; |
| 107 | |
| 108 | /* If we get this far, the user specified a valid integer. |
| 109 | * However we do not currently support the use of negative |
| 110 | * numbers as CMOS parameter values. |
| 111 | */ |
| 112 | if (negative) |
| 113 | return CMOS_OP_NEGATIVE_INT; |
| 114 | |
| 115 | break; |
| 116 | |
| 117 | case CMOS_ENTRY_STRING: |
| 118 | if (e->length < (8 * strlen(value_str))) |
| 119 | return CMOS_OP_VALUE_TOO_WIDE; |
| 120 | memory = malloc(e->length / 8); |
| 121 | memset(memory, 0, e->length / 8); |
no test coverage detected