| 90 | } |
| 91 | |
| 92 | static uint64_t parse_uint(const char source[], |
| 93 | const char type[], |
| 94 | unsigned long long max, |
| 95 | bool *failed) |
| 96 | { |
| 97 | char *end; |
| 98 | unsigned long long uint = strtoull(source, &end, /*base=*/0); |
| 99 | if (*end != '\0') { |
| 100 | fprintf(stderr, "Trailing characters in \"%s\": %s\n", |
| 101 | source, end); |
| 102 | *failed = true; |
| 103 | return 0; |
| 104 | } |
| 105 | if (uint > max) { |
| 106 | fprintf(stderr, "Invalid %s value: %llu\n", type, uint); |
| 107 | *failed = true; |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | *failed = false; |
| 112 | return uint; |
| 113 | } |
| 114 | |
| 115 | void *make_data(const char source[], size_t *data_size, enum data_type type) |
| 116 | { |