| 16 | } |
| 17 | |
| 18 | int git_parse_signed(const char *value, intmax_t *ret, intmax_t max) |
| 19 | { |
| 20 | if (value && *value) { |
| 21 | char *end; |
| 22 | intmax_t val; |
| 23 | intmax_t factor; |
| 24 | |
| 25 | if (max < 0) |
| 26 | BUG("max must be a positive integer"); |
| 27 | |
| 28 | errno = 0; |
| 29 | val = strtoimax(value, &end, 0); |
| 30 | if (errno == ERANGE) |
| 31 | return 0; |
| 32 | if (end == value) { |
| 33 | errno = EINVAL; |
| 34 | return 0; |
| 35 | } |
| 36 | factor = get_unit_factor(end); |
| 37 | if (!factor) { |
| 38 | errno = EINVAL; |
| 39 | return 0; |
| 40 | } |
| 41 | if ((val < 0 && (-max - 1) / factor > val) || |
| 42 | (val > 0 && max / factor < val)) { |
| 43 | errno = ERANGE; |
| 44 | return 0; |
| 45 | } |
| 46 | val *= factor; |
| 47 | *ret = val; |
| 48 | return 1; |
| 49 | } |
| 50 | errno = EINVAL; |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max) |
| 55 | { |
no test coverage detected