diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2016-01-14 01:22:41 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-01-14 11:56:04 +0100 |
commit | 73928b158a1190c55b22418faf5cd3f3204108d1 (patch) | |
tree | fb8e9b6be8ad556c859c5bee14cd03c10288dbd1 /trafgen.c | |
parent | 6f6a60c2aa03796bd9abd512a5aa0eeb48f3d09e (diff) |
trafgen: Simplify ring size unit parsing
Lets strtoul(...) func set pointer of unit name for ring size option,
instead of check each character by isdigit(...).
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen.c')
-rw-r--r-- | trafgen.c | 19 |
1 files changed, 7 insertions, 12 deletions
@@ -978,7 +978,7 @@ int main(int argc, char **argv) bool prio_high = false, set_irq_aff = true, set_sock_mem = true; int c, opt_index, vals[4] = {0}, irq; uint64_t gap = 0; - unsigned int i, j; + unsigned int i; char *confname = NULL, *ptr; unsigned long cpus_tmp, orig_num = 0; unsigned long long tx_packets, tx_bytes; @@ -1155,24 +1155,19 @@ int main(int argc, char **argv) shaper_set_rate(&ctx.sh, rate, shape_type); break; case 'S': - ptr = optarg; - - for (j = i = strlen(optarg); i > 0; --i) { - if (!isdigit(optarg[j - i])) - break; - ptr++; - } + ctx.reserve_size = strtoul(optarg, &ptr, 0); + if (ctx.reserve_size == 0 && ptr == optarg) + panic("Invalid ring size param\n"); if (!strncmp(ptr, "KiB", strlen("KiB"))) - ctx.reserve_size = 1 << 10; + ctx.reserve_size *= 1 << 10; else if (!strncmp(ptr, "MiB", strlen("MiB"))) ctx.reserve_size = 1 << 20; else if (!strncmp(ptr, "GiB", strlen("GiB"))) - ctx.reserve_size = 1 << 30; + ctx.reserve_size *= 1 << 30; else - panic("Syntax error in ring size param!\n"); + panic("Invalid ring size unit type\n"); - ctx.reserve_size *= strtoul(optarg, NULL, 0); break; case '?': switch (optopt) { |