* bootstrap.conf (gnulib_modules): Add stdcountof-h.
* src/system.h: Include stdcountof.h.
(ARRAY_CARDINALITY): Remove definition.
* .gitignore (/lib/stdcountof.h): Ignore Gnulib generated file.
* src/csplit.c: Use countof instead of ARRAY_CARDINALITY.
* src/df.c: Likewise.
* src/digest.c: Likewise.
* src/dircolors.c: Likewise.
* src/factor.c: Likewise.
* src/join.c: Likewise.
* src/ls.c: Likewise.
* src/od.c: Likewise.
* src/sort.c: Likewise.
* src/stdbuf.c: Likewise.
* src/tr.c: Likewise.
/lib/stdarg.h
/lib/stdbool.h
/lib/stdbit.h
+/lib/stdcountof.h
/lib/stdckdint.h
/lib/stddef.h
/lib/stdint.h
stdc_leading_zeros
stdc_trailing_zeros
stdckdint-h
+ stdcountof-h
stddef-h
stdlib-safer
stpcpy
SIGXFSZ,
#endif
};
- enum { nsigs = ARRAY_CARDINALITY (sig) };
+ enum { nsigs = countof (sig) };
struct sigaction act;
/* 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))
{
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;
"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;
};
#undef P
-enum { PRIMES_PTAB_ENTRIES = ARRAY_CARDINALITY (primes_ptab) - 8 + 1 };
+enum { PRIMES_PTAB_ENTRIES = countof (primes_ptab) - 8 + 1 };
struct primes_dtab
{
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])
{
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[] =
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] =
SIGXFSZ,
#endif
};
- enum { nsigs = ARRAY_CARDINALITY (sig) };
+ enum { nsigs = countof (sig) };
#if ! SA_NOCLDSTOP
static bool caught_sig[nsigs];
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;
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]))
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. */
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
/* 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] =
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"
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)))
SIGXFSZ,
#endif
};
- enum { nsigs = ARRAY_CARDINALITY (sig) };
+ enum { nsigs = countof (sig) };
#if SA_NOCLDSTOP
struct sigaction act;
{
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)
{
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++;
#endif
#include <stdckdint.h>
+#include <stdcountof.h>
#include <stddef.h>
#include <string.h>
#include <uchar.h>
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
{
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;