Introduce enum n2s_unit
authorBart Van Assche <bart.vanassche@wdc.com>
Wed, 4 Apr 2018 21:36:40 +0000 (14:36 -0700)
committerBart Van Assche <bart.vanassche@wdc.com>
Wed, 18 Apr 2018 20:25:30 +0000 (13:25 -0700)
This patch does not change any functionality but makes num2str() slightly
easier to read.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
init.c
lib/num2str.c
lib/num2str.h
options.c

diff --git a/init.c b/init.c
index 07d1cdd31df2b1cba4f4ce8a07b3c4ed96e92353..9257d47c0180af0ff4635418eb4718d254297df4 100644 (file)
--- 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
index 387c5d7b322dc1947d095c9eeed03a8b3fae75a4..71d65e04fe7730a777e5eb249b4a9e043cb944d6 100644 (file)
  * @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[<unit prefix>][<units>]"
  */
-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;
index 81358a1e3a4c734fd2c81f3afa73c8395c4d1f62..ad61e2408248f7865fcc4dc1dcbb5363f4f0619e 100644 (file)
@@ -3,13 +3,15 @@
 
 #include <inttypes.h>
 
-#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
index 1b3ea04d203ac84c0a9179310182eb089518c26c..0b3a895d14d83ab00d5c495b9393e307bba1c4c2 100644 (file)
--- 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",
                          },
                },