From bf8eb6dcc7f9d1318ddeac16fe62a5b5f818524b Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 26 May 2023 08:43:24 +0200 Subject: check_disk: Display SI units correctly --- plugins/check_disk.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/plugins/check_disk.c b/plugins/check_disk.c index a99f35e3..39dc6cd2 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -626,21 +626,36 @@ process_arguments (int argc, char **argv) if (! strcasecmp (optarg, "bytes")) { mult = (uintmax_t)1; units = strdup ("B"); - } else if ( (! strcmp (optarg, "kB")) || (!strcmp(optarg, "KiB")) ) { + } else if (!strcmp(optarg, "KiB")) { mult = (uintmax_t)1024; - units = strdup ("kiB"); - } else if ( (! strcmp (optarg, "MB")) || (!strcmp(optarg, "MiB")) ) { + units = strdup ("KiB"); + } else if (! strcmp (optarg, "kB")) { + mult = (uintmax_t)1000; + units = strdup ("kB"); + } else if (!strcmp(optarg, "MiB")) { mult = (uintmax_t)1024 * 1024; units = strdup ("MiB"); - } else if ( (! strcmp (optarg, "GB")) || (!strcmp(optarg, "GiB")) ) { + } else if (! strcmp (optarg, "MB")) { + mult = (uintmax_t)1000 * 1000; + units = strdup ("MB"); + } else if (!strcmp(optarg, "GiB")) { mult = (uintmax_t)1024 * 1024 * 1024; units = strdup ("GiB"); - } else if ( (! strcmp (optarg, "TB")) || (!strcmp(optarg, "TiB")) ) { + } else if (! strcmp (optarg, "GB")){ + mult = (uintmax_t)1000 * 1000 * 1000; + units = strdup ("GB"); + } else if (!strcmp(optarg, "TiB")) { mult = (uintmax_t)1024 * 1024 * 1024 * 1024; units = strdup ("TiB"); - } else if ( (! strcmp (optarg, "PB")) || (!strcmp(optarg, "PiB")) ) { + } else if (! strcmp (optarg, "TB")) { + mult = (uintmax_t)1000 * 1000 * 1000 * 1000; + units = strdup ("TB"); + } else if (!strcmp(optarg, "PiB")) { mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024; units = strdup ("PiB"); + } else if (! strcmp (optarg, "PB")){ + mult = (uintmax_t)1000 * 1000 * 1000 * 1000 * 1000; + units = strdup ("PB"); } else { die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); } -- cgit v1.2.3-74-g34f1