Parse a size, optionally ending in 'K', 'M' */
| 550 | |
| 551 | /* Parse a size, optionally ending in 'K', 'M' */ |
| 552 | static long parse_bytes(const char *valstring) |
| 553 | { |
| 554 | unsigned int value; |
| 555 | int multiplier = 1; |
| 556 | char suffix = '\0'; |
| 557 | int have_suffix = 0; |
| 558 | |
| 559 | /* Suffix is optional */ |
| 560 | if (sscanf(valstring, "%u%c", &value, &suffix) == 0) { |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | if (toupper(suffix) == 'M') { |
| 565 | multiplier = 1024*1024; |
| 566 | have_suffix = 1; |
| 567 | } |
| 568 | if (toupper(suffix) == 'K') { |
| 569 | multiplier = 1024; |
| 570 | have_suffix = 1; |
| 571 | } |
| 572 | |
| 573 | if (!have_suffix && suffix != '\0') { |
| 574 | fprintf(stderr, "Invalid suffix '%c', only K or M supported\n", suffix); |
| 575 | return 0; |
| 576 | } |
| 577 | return value * multiplier; |
| 578 | } |
| 579 | |
| 580 | static int connect_and_join(int model, int verbose) |
| 581 | { |