From 41a87019871503bb85e19e622b6a5f47de6c2aeb Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 4 Apr 2018 14:36:40 -0700 Subject: [PATCH] Introduce enum n2s_unit This patch does not change any functionality but makes num2str() slightly easier to read. Signed-off-by: Bart Van Assche --- init.c | 6 +++--- lib/num2str.c | 6 ++++-- lib/num2str.h | 18 ++++++++++-------- options.c | 6 +++--- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/init.c b/init.c index 07d1cdd3..9257d47c 100644 --- a/init.c +++ b/init.c @@ -833,11 +833,11 @@ static int fixup_options(struct thread_data *td) } } - if (!o->unit_base) { + if (o->unit_base == N2S_NONE) { if (td_ioengine_flagged(td, FIO_BIT_BASED)) - o->unit_base = 1; + o->unit_base = N2S_BITPERSEC; else - o->unit_base = 8; + o->unit_base = N2S_BYTEPERSEC; } #ifndef FIO_HAVE_ANY_FALLOCATE diff --git a/lib/num2str.c b/lib/num2str.c index 387c5d7b..71d65e04 100644 --- a/lib/num2str.c +++ b/lib/num2str.c @@ -14,10 +14,10 @@ * @maxlen: max number of digits in the output string (not counting prefix and units, but counting .) * @base: multiplier for num (e.g., if num represents Ki, use 1024) * @pow2: select unit prefix - 0=power-of-10 decimal SI, nonzero=power-of-2 binary IEC - * @units: select units - N2S_* macros defined in num2str.h + * @units: select units - N2S_* constants defined in num2str.h * @returns a malloc'd buffer containing "number[][]" */ -char *num2str(uint64_t num, int maxlen, int base, int pow2, int units) +char *num2str(uint64_t num, int maxlen, int base, int pow2, enum n2s_unit units) { const char *sistr[] = { "", "k", "M", "G", "T", "P" }; const char *iecstr[] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" }; @@ -44,6 +44,8 @@ char *num2str(uint64_t num, int maxlen, int base, int pow2, int units) base /= thousand[!!pow2]; switch (units) { + case N2S_NONE: + break; case N2S_PERSEC: unit_index = 1; break; diff --git a/lib/num2str.h b/lib/num2str.h index 81358a1e..ad61e240 100644 --- a/lib/num2str.h +++ b/lib/num2str.h @@ -3,13 +3,15 @@ #include -#define N2S_NONE 0 -#define N2S_BITPERSEC 1 /* match unit_base for bit rates */ -#define N2S_PERSEC 2 -#define N2S_BIT 3 -#define N2S_BYTE 4 -#define N2S_BYTEPERSEC 8 /* match unit_base for byte rates */ - -extern char *num2str(uint64_t, int, int, int, int); +enum n2s_unit { + N2S_NONE = 0, + N2S_BITPERSEC = 1, + N2S_PERSEC = 2, + N2S_BIT = 3, + N2S_BYTE = 4, + N2S_BYTEPERSEC = 8, +}; + +extern char *num2str(uint64_t, int, int, int, enum n2s_unit); #endif diff --git a/options.c b/options.c index 1b3ea04d..0b3a895d 100644 --- a/options.c +++ b/options.c @@ -4425,15 +4425,15 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .prio = 1, .posval = { { .ival = "0", - .oval = 0, + .oval = N2S_NONE, .help = "Auto-detect", }, { .ival = "8", - .oval = 8, + .oval = N2S_BYTEPERSEC, .help = "Normal (byte based)", }, { .ival = "1", - .oval = 1, + .oval = N2S_BITPERSEC, .help = "Bit based", }, }, -- 2.25.1