Set size to the value of STR, interpreted as a decimal integer, optionally multiplied by various values. Return -1 on error, 0 on success. This supports dd BLOCK size suffixes. Note we don't support dd's b=512, c=1, w=2 or 21x512MiB formats. */
| 61 | This supports dd BLOCK size suffixes. |
| 62 | Note we don't support dd's b=512, c=1, w=2 or 21x512MiB formats. */ |
| 63 | static int |
| 64 | parse_size (char const *str, size_t *size) |
| 65 | { |
| 66 | uintmax_t tmp_size; |
| 67 | enum strtol_error e = xstrtoumax (str, NULL, 10, |
| 68 | &tmp_size, "EGkKMPQRTYZ0"); |
| 69 | if (e == LONGINT_OK && SIZE_MAX < tmp_size) |
| 70 | e = LONGINT_OVERFLOW; |
| 71 | |
| 72 | if (e == LONGINT_OK) |
| 73 | { |
| 74 | errno = 0; |
| 75 | *size = tmp_size; |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | errno = (e == LONGINT_OVERFLOW ? EOVERFLOW : errno); |
| 80 | return -1; |
| 81 | } |
| 82 | |
| 83 | void |
| 84 | usage (int status) |