MCPcopy Create free account
hub / github.com/corosync/corosync / parse_bytes

Function parse_bytes

test/cpghum.c:552–578  ·  view source on GitHub ↗

Parse a size, optionally ending in 'K', 'M' */

Source from the content-addressed store, hash-verified

550
551/* Parse a size, optionally ending in 'K', 'M' */
552static 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
580static int connect_and_join(int model, int verbose)
581{

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected