#define str_endswith(s, suffix) \
(strlen(s) >= strlen(suffix) \
&& str_eq((s) + strlen(s) - strlen(suffix), (suffix)))
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
// Buffer size for I/O operations. Should be a multiple of 4 KiB.
#define READ_BUFFER_SIZE 65536
-// Copyright (C) 2010-2016 Joel Rosdahl
+// Copyright (C) 2010-2018 Joel Rosdahl
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
struct compopt key;
key.name = option;
return bsearch(
- &key, compopts, sizeof(compopts) / sizeof(compopts[0]),
- sizeof(compopts[0]), compare_compopts);
+ &key, compopts, ARRAY_SIZE(compopts), sizeof(compopts[0]),
+ compare_compopts);
}
static const struct compopt *
struct compopt key;
key.name = option;
return bsearch(
- &key, compopts, sizeof(compopts) / sizeof(compopts[0]),
- sizeof(compopts[0]), compare_prefix_compopts);
+ &key, compopts, ARRAY_SIZE(compopts), sizeof(compopts[0]),
+ compare_prefix_compopts);
}
// Runs fn on the first two characters of option.
bool
compopt_verify_sortedness(void)
{
- for (size_t i = 1; i < sizeof(compopts)/sizeof(compopts[0]); i++) {
+ for (size_t i = 1; i < ARRAY_SIZE(compopts); i++) {
if (strcmp(compopts[i-1].name, compopts[i].name) >= 0) {
fprintf(stderr,
"compopt_verify_sortedness: %s >= %s\n",
-// Copyright (C) 2010-2016 Joel Rosdahl
+// Copyright (C) 2010-2018 Joel Rosdahl
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
};
- for (i = 0; i < sizeof(sizes) / sizeof(sizes[0]); ++i) {
+ for (i = 0; i < ARRAY_SIZE(sizes); ++i) {
CHECKM(parse_size_with_suffix(sizes[i].size, &size), sizes[i].size);
CHECK_INT_EQ(sizes[i].expected, size);
}