btrfs-progs: use predefined getopt values for unit suffixes
authorDavid Sterba <dsterba@suse.cz>
Wed, 21 Jan 2015 17:09:32 +0000 (18:09 +0100)
committerDavid Sterba <dsterba@suse.cz>
Wed, 21 Jan 2015 17:32:06 +0000 (18:32 +0100)
Signed-off-by: David Sterba <dsterba@suse.cz>
cmds-device.c
cmds-qgroup.c

index ba9e6b3..ce4406f 100644 (file)
@@ -509,8 +509,8 @@ int cmd_device_usage(int argc, char **argv)
                        { "mbytes", no_argument, NULL, 'm'},
                        { "gbytes", no_argument, NULL, 'g'},
                        { "tbytes", no_argument, NULL, 't'},
-                       { "si", no_argument, NULL, 256},
-                       { "iec", no_argument, NULL, 257},
+                       { "si", no_argument, NULL, GETOPT_VAL_SI},
+                       { "iec", no_argument, NULL, GETOPT_VAL_IEC},
                };
                int c = getopt_long(argc, argv, "bhHkmgt", long_options,
                                &long_index);
@@ -539,10 +539,10 @@ int cmd_device_usage(int argc, char **argv)
                case 'H':
                        unit_mode = UNITS_HUMAN_DECIMAL;
                        break;
-               case 256:
+               case GETOPT_VAL_SI:
                        units_set_mode(&unit_mode, UNITS_DECIMAL);
                        break;
-               case 257:
+               case GETOPT_VAL_IEC:
                        units_set_mode(&unit_mode, UNITS_BINARY);
                        break;
                default:
index 26c8791..5ee7162 100644 (file)
@@ -253,11 +253,11 @@ static int cmd_qgroup_show(int argc, char **argv)
                int option_index = 0;
                static const struct option long_options[] = {
                        {"sort", 1, NULL, 'S'},
-                       {"raw", no_argument, NULL, 0},
-                       {"kbytes", no_argument, NULL, 0},
-                       {"mbytes", no_argument, NULL, 0},
-                       {"gbytes", no_argument, NULL, 0},
-                       {"tbytes", no_argument, NULL, 0},
+                       {"raw", no_argument, NULL, GETOPT_VAL_RAW},
+                       {"kbytes", no_argument, NULL, GETOPT_VAL_KBYTES},
+                       {"mbytes", no_argument, NULL, GETOPT_VAL_MBYTES},
+                       {"gbytes", no_argument, NULL, GETOPT_VAL_GBYTES},
+                       {"tbytes", no_argument, NULL, GETOPT_VAL_TBYTES},
                        {"si", no_argument, NULL, GETOPT_VAL_SI},
                        {"iec", no_argument, NULL, GETOPT_VAL_IEC},
                        {0, 0, 0, 0}
@@ -296,17 +296,20 @@ static int cmd_qgroup_show(int argc, char **argv)
                        if (ret)
                                usage(cmd_qgroup_show_usage);
                        break;
-               case 0:
-                       if (option_index == 1)
-                               unit_mode = UNITS_RAW;
-                       else if (option_index == 2)
-                               units_set_base(&unit_mode, UNITS_KBYTES);
-                       else if (option_index == 3)
-                               units_set_base(&unit_mode, UNITS_MBYTES);
-                       else if (option_index == 4)
-                               units_set_base(&unit_mode, UNITS_GBYTES);
-                       else if (option_index == 5)
-                               units_set_base(&unit_mode, UNITS_TBYTES);
+               case GETOPT_VAL_RAW:
+                       unit_mode = UNITS_RAW;
+                       break;
+               case GETOPT_VAL_KBYTES:
+                       units_set_base(&unit_mode, UNITS_KBYTES);
+                       break;
+               case GETOPT_VAL_MBYTES:
+                       units_set_base(&unit_mode, UNITS_MBYTES);
+                       break;
+               case GETOPT_VAL_GBYTES:
+                       units_set_base(&unit_mode, UNITS_GBYTES);
+                       break;
+               case GETOPT_VAL_TBYTES:
+                       units_set_base(&unit_mode, UNITS_TBYTES);
                        break;
                case GETOPT_VAL_SI:
                        units_set_mode(&unit_mode, UNITS_DECIMAL);