Remove cool, comfy c23 functionality for some dirty old hacks

This commit is contained in:
Lorenz Kästle 2025-03-30 23:30:51 +02:00
parent c4fd34ed79
commit a4cf2e79f7
3 changed files with 50 additions and 32 deletions

View file

@ -96,6 +96,22 @@ static void print_help(void);
static int verbose = 0;
// This would not be necessary in C23!!
const byte_unit Bytes_Factor = 1;
const byte_unit KibiBytes_factor = 1024;
const byte_unit MebiBytes_factor = 1048576;
const byte_unit GibiBytes_factor = 1073741824;
const byte_unit TebiBytes_factor = 1099511627776;
const byte_unit PebiBytes_factor = 1125899906842624;
const byte_unit ExbiBytes_factor = 1152921504606846976;
const byte_unit KiloBytes_factor = 1000;
const byte_unit MegaBytes_factor = 1000000;
const byte_unit GigaBytes_factor = 1000000000;
const byte_unit TeraBytes_factor = 1000000000000;
const byte_unit PetaBytes_factor = 1000000000000000;
const byte_unit ExaBytes_factor = 1000000000000000000;
int main(int argc, char **argv) {
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@ -409,7 +425,7 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
bool path_selected = false;
char *group = NULL;
byte_unit unit = MebiBytes;
byte_unit unit = MebiBytes_factor;
result.config.mount_list = read_file_system_list(false);
@ -494,25 +510,25 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
break;
case 'u':
if (!strcasecmp(optarg, "bytes")) {
unit = Bytes;
unit = Bytes_Factor;
} else if (!strcmp(optarg, "KiB")) {
unit = KibiBytes;
unit = KibiBytes_factor;
} else if (!strcmp(optarg, "kB")) {
unit = KiloBytes;
unit = KiloBytes_factor;
} else if (!strcmp(optarg, "MiB")) {
unit = MebiBytes;
unit = MebiBytes_factor;
} else if (!strcmp(optarg, "MB")) {
unit = MegaBytes;
unit = MegaBytes_factor;
} else if (!strcmp(optarg, "GiB")) {
unit = GibiBytes;
unit = MegaBytes_factor;
} else if (!strcmp(optarg, "GB")) {
unit = GigaBytes;
unit = MegaBytes_factor;
} else if (!strcmp(optarg, "TiB")) {
unit = TebiBytes;
unit = MegaBytes_factor;
} else if (!strcmp(optarg, "TB")) {
unit = TeraBytes;
unit = MegaBytes_factor;
} else if (!strcmp(optarg, "PiB")) {
unit = PebiBytes;
unit = MegaBytes_factor;
} else if (!strcmp(optarg, "PB")) {
unit = PetaBytes;
} else {
@ -520,10 +536,10 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
}
break;
case 'k':
unit = KibiBytes;
unit = KibiBytes_factor;
break;
case 'm':
unit = MebiBytes;
unit = MebiBytes_factor;
break;
case display_unit_index:
if (!strcasecmp(optarg, "bytes")) {

View file

@ -180,7 +180,7 @@ check_disk_config check_disk_config_init() {
return tmp;
}
char *get_unit_string(byte_unit unit) {
char *get_unit_string(byte_unit_enum unit) {
switch (unit) {
case Bytes:
return "Bytes";

View file

@ -8,22 +8,24 @@
#include "regex.h"
#include <stdint.h>
typedef enum : unsigned long {
Humanized = 0,
Bytes = 1,
KibiBytes = 1024,
MebiBytes = 1024 * KibiBytes,
GibiBytes = 1024 * MebiBytes,
TebiBytes = 1024 * GibiBytes,
PebiBytes = 1024 * TebiBytes,
ExbiBytes = 1024 * PebiBytes,
KiloBytes = 1000,
MegaBytes = 1000 * KiloBytes,
GigaBytes = 1000 * MegaBytes,
TeraBytes = 1000 * GigaBytes,
PetaBytes = 1000 * TeraBytes,
ExaBytes = 1000 * PetaBytes
} byte_unit;
typedef unsigned long long byte_unit;
typedef enum {
Humanized,
Bytes,
KibiBytes,
MebiBytes,
GibiBytes,
TebiBytes,
PebiBytes,
ExbiBytes,
KiloBytes,
MegaBytes,
GigaBytes,
TeraBytes,
PetaBytes,
ExaBytes,
} byte_unit_enum;
typedef struct name_list string_list;
struct name_list {
@ -120,7 +122,7 @@ typedef struct {
struct mount_entry *mount_list;
struct name_list *seen;
byte_unit display_unit;
byte_unit_enum display_unit;
// byte_unit unit;
bool output_format_is_set;
@ -149,7 +151,7 @@ measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem fil
int search_parameter_list(parameter_list_elem *list, const char *name);
bool np_regex_match_mount_entry(struct mount_entry *, regex_t *);
char *get_unit_string(byte_unit);
char *get_unit_string(byte_unit_enum);
check_disk_config check_disk_config_init();
char *humanize_byte_value(uintmax_t value, bool use_si_units);