aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/csplit.c2
-rw-r--r--src/df.c2
-rw-r--r--src/digest.c3
-rw-r--r--src/dircolors.c2
-rw-r--r--src/factor.c2
-rw-r--r--src/join.c2
-rw-r--r--src/ls.c17
-rw-r--r--src/od.c6
-rw-r--r--src/sort.c2
-rw-r--r--src/stdbuf.c4
-rw-r--r--src/system.h5
-rw-r--r--src/tr.c2
12 files changed, 21 insertions, 28 deletions
diff --git a/src/csplit.c b/src/csplit.c
index de499f166..d2a928ae6 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -1392,7 +1392,7 @@ main (int argc, char **argv)
SIGXFSZ,
#endif
};
- enum { nsigs = ARRAY_CARDINALITY (sig) };
+ enum { nsigs = countof (sig) };
struct sigaction act;
diff --git a/src/df.c b/src/df.c
index 857f76cf4..75e638c5e 100644
--- a/src/df.c
+++ b/src/df.c
@@ -441,7 +441,7 @@ decode_output_arg (char const *arg)
/* process S. */
display_field_t field = INVALID_FIELD;
- for (idx_t i = 0; i < ARRAY_CARDINALITY (field_data); i++)
+ for (idx_t i = 0; i < countof (field_data); i++)
{
if (streq (field_data[i].arg, s))
{
diff --git a/src/digest.c b/src/digest.c
index 64c2c49b1..ce0e222e1 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -376,8 +376,7 @@ static int const algorithm_bits[] =
512, 512, 512, 256, 0
};
-static_assert (ARRAY_CARDINALITY (algorithm_bits)
- == ARRAY_CARDINALITY (algorithm_args));
+static_assert (countof (algorithm_bits) == countof (algorithm_args));
static bool algorithm_specified = false;
static enum Algorithm cksum_algorithm = crc;
diff --git a/src/dircolors.c b/src/dircolors.c
index cb6714dbf..19e815953 100644
--- a/src/dircolors.c
+++ b/src/dircolors.c
@@ -67,7 +67,7 @@ static char const *const ls_codes[] =
"su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", "mh", "cl",
nullptr
};
-static_assert (ARRAY_CARDINALITY (slack_codes) == ARRAY_CARDINALITY (ls_codes));
+static_assert (countof (slack_codes) == countof (ls_codes));
/* Whether to output escaped ls color codes for display. */
static bool print_ls_colors;
diff --git a/src/factor.c b/src/factor.c
index 534490e9b..02b02a977 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -720,7 +720,7 @@ static int_least16_t const primes_ptab[] = {
};
#undef P
-enum { PRIMES_PTAB_ENTRIES = ARRAY_CARDINALITY (primes_ptab) - 8 + 1 };
+enum { PRIMES_PTAB_ENTRIES = countof (primes_ptab) - 8 + 1 };
struct primes_dtab
{
diff --git a/src/join.c b/src/join.c
index 28d9dd3ee..5cf87d1e8 100644
--- a/src/join.c
+++ b/src/join.c
@@ -488,7 +488,7 @@ get_line (FILE *fp, struct line **linep, int which)
static void
free_spareline (void)
{
- for (idx_t i = 0; i < ARRAY_CARDINALITY (spareline); i++)
+ for (idx_t i = 0; i < countof (spareline); i++)
{
if (spareline[i])
{
diff --git a/src/ls.c b/src/ls.c
index d999d5bdf..447089422 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -180,7 +180,7 @@ enum { filetype_cardinality = arg_directory + 1 };
Keep these in sync with enum filetype. */
static char const filetype_letter[] =
{'?', 'p', 'c', 'd', 'b', '-', 'l', 's', 'w', 'd'};
-static_assert (ARRAY_CARDINALITY (filetype_letter) == filetype_cardinality);
+static_assert (countof (filetype_letter) == filetype_cardinality);
/* Map enum filetype to <dirent.h> d_type values. */
static unsigned char const filetype_d_type[] =
@@ -188,7 +188,7 @@ static unsigned char const filetype_d_type[] =
DT_UNKNOWN, DT_FIFO, DT_CHR, DT_DIR, DT_BLK, DT_REG, DT_LNK, DT_SOCK,
DT_WHT, DT_DIR
};
-static_assert (ARRAY_CARDINALITY (filetype_d_type) == filetype_cardinality);
+static_assert (countof (filetype_d_type) == filetype_cardinality);
/* Map d_type values to enum filetype. */
static char const d_type_filetype[UCHAR_MAX + 1] =
@@ -1621,7 +1621,7 @@ signal_setup (bool init)
SIGXFSZ,
#endif
};
- enum { nsigs = ARRAY_CARDINALITY (sig) };
+ enum { nsigs = countof (sig) };
#if ! SA_NOCLDSTOP
static bool caught_sig[nsigs];
@@ -1705,8 +1705,7 @@ main (int argc, char **argv)
initialize_exit_failure (LS_FAILURE);
atexit (close_stdout);
- static_assert (ARRAY_CARDINALITY (color_indicator)
- == ARRAY_CARDINALITY (indicator_name));
+ static_assert (countof (color_indicator) == countof (indicator_name));
exit_status = EXIT_SUCCESS;
print_dir_name = true;
@@ -2823,7 +2822,7 @@ parse_ls_color (void)
state = PS_FAIL; /* Assume failure... */
if (*(p++) == '=')/* It *should* be... */
{
- for (int i = 0; i < ARRAY_CARDINALITY (indicator_name); i++)
+ for (int i = 0; i < countof (indicator_name); i++)
{
if ((label0 == indicator_name[i][0])
&& (label1 == indicator_name[i][1]))
@@ -4036,8 +4035,7 @@ static qsortFunc const sort_functions[][2][2][2] =
This line verifies at compile-time that the array of sort functions has been
initialized for all possible sort keys. */
-static_assert (ARRAY_CARDINALITY (sort_functions)
- == sort_numtypes - 2 + time_numtypes);
+static_assert (countof (sort_functions) == sort_numtypes - 2 + time_numtypes);
/* Set up SORTED_FILE to point to the in-use entries in CWD_FILE, in order. */
@@ -4986,8 +4984,7 @@ get_color_indicator (const struct fileinfo *f, bool symlink_target)
C_ORPHAN, C_FIFO, C_CHR, C_DIR, C_BLK, C_FILE,
C_LINK, C_SOCK, C_FILE, C_DIR
};
- static_assert (ARRAY_CARDINALITY (filetype_indicator)
- == filetype_cardinality);
+ static_assert (countof (filetype_indicator) == filetype_cardinality);
type = filetype_indicator[f->filetype];
}
else
diff --git a/src/od.c b/src/od.c
index f8937298f..946b6517f 100644
--- a/src/od.c
+++ b/src/od.c
@@ -167,7 +167,7 @@ static const int width_bytes[] =
/* Ensure that for each member of 'enum size_spec' there is an
initializer in the width_bytes array. */
-static_assert (ARRAY_CARDINALITY (width_bytes) == N_SIZE_SPECS);
+static_assert (countof (width_bytes) == N_SIZE_SPECS);
/* Names for some non-printing characters. */
static char const charname[33][4] =
@@ -761,7 +761,7 @@ decode_one_format (char const *s_orig, char const *s, char const **next,
size = sizeof (unsigned int);
else
{
- if (ARRAY_CARDINALITY (integral_type_size) <= size
+ if (countof (integral_type_size) <= size
|| integral_type_size[size] == NO_SIZE)
{
error (0, 0, _("invalid type string %s;\nthis system"
@@ -873,7 +873,7 @@ decode_one_format (char const *s_orig, char const *s, char const **next,
size = sizeof (double);
else
{
- if (ARRAY_CARDINALITY (fp_type_size) <= size
+ if (countof (fp_type_size) <= size
|| fp_type_size[size] == NO_SIZE
|| (! FLOAT16_SUPPORTED && BF16_SUPPORTED
&& size == sizeof (bfloat16)))
diff --git a/src/sort.c b/src/sort.c
index 5a6a963f3..0212695b1 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -4416,7 +4416,7 @@ main (int argc, char **argv)
SIGXFSZ,
#endif
};
- enum { nsigs = ARRAY_CARDINALITY (sig) };
+ enum { nsigs = countof (sig) };
#if SA_NOCLDSTOP
struct sigaction act;
diff --git a/src/stdbuf.c b/src/stdbuf.c
index 11b9a12f2..c3d72ce5f 100644
--- a/src/stdbuf.c
+++ b/src/stdbuf.c
@@ -279,7 +279,7 @@ set_libstdbuf_options (void)
{
bool env_set = false;
- for (size_t i = 0; i < ARRAY_CARDINALITY (stdbuf); i++)
+ for (size_t i = 0; i < countof (stdbuf); i++)
{
if (stdbuf[i].optarg)
{
@@ -333,7 +333,7 @@ main (int argc, char **argv)
case 'i':
case 'o':
opt_fileno = optc_to_fileno (c);
- affirm (0 <= opt_fileno && opt_fileno < ARRAY_CARDINALITY (stdbuf));
+ affirm (0 <= opt_fileno && opt_fileno < countof (stdbuf));
stdbuf[opt_fileno].optc = c;
while (c_isspace (*optarg))
optarg++;
diff --git a/src/system.h b/src/system.h
index a7ae5a5f3..b8612ff5e 100644
--- a/src/system.h
+++ b/src/system.h
@@ -68,6 +68,7 @@
#endif
#include <stdckdint.h>
+#include <stdcountof.h>
#include <stddef.h>
#include <string.h>
#include <uchar.h>
@@ -770,10 +771,6 @@ stzncpy (char *restrict dest, char const *restrict src, size_t len)
return dest;
}
-#ifndef ARRAY_CARDINALITY
-# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
-#endif
-
/* Return true if ERR is ENOTSUP or EOPNOTSUPP, otherwise false.
This wrapper function avoids the redundant 'or'd comparison on
systems like Linux for which they have the same value. It also
diff --git a/src/tr.c b/src/tr.c
index 87daa9471..f172ced86 100644
--- a/src/tr.c
+++ b/src/tr.c
@@ -545,7 +545,7 @@ look_up_char_class (char const *class_str, size_t len)
{
enum Char_class i;
- for (i = 0; i < ARRAY_CARDINALITY (char_class_name); i++)
+ for (i = 0; i < countof (char_class_name); i++)
if (STREQ_LEN (class_str, char_class_name[i], len)
&& strlen (char_class_name[i]) == len)
return i;