maint: use ARRAY_CARDINALITY more
authorJim Meyering <meyering@redhat.com>
Sun, 17 May 2009 11:02:25 +0000 (13:02 +0200)
committerJim Meyering <meyering@redhat.com>
Sun, 17 May 2009 11:59:12 +0000 (13:59 +0200)
* src/sort.c (main): Use ARRAY_CARDINALITY, rather than open-coding it.
* src/factor.c (WHEEL_END): Likewise.
* src/csplit.c (main): Likewise.
* src/od.c: Likewise,
* src/ls.c (main): Likewise.
(N_ENTRIES): Remove definition.  Use ARRAY_CARDINALITY instead.
* src/dircolors.c: Likewise.
(array_len): Remove definition.

src/csplit.c
src/dircolors.c
src/factor.c
src/ls.c
src/od.c
src/sort.c

index 4f0beb6..b2892c9 100644 (file)
@@ -1403,7 +1403,7 @@ main (int argc, char **argv)
        SIGXFSZ,
 #endif
       };
-    enum { nsigs = sizeof sig / sizeof sig[0] };
+    enum { nsigs = ARRAY_CARDINALITY (sig) };
 
     struct sigaction act;
 
index 7dad7fd..f01d557 100644 (file)
@@ -1,5 +1,5 @@
 /* dircolors - output commands to set the LS_COLOR environment variable
-   Copyright (C) 1996-2008 Free Software Foundation, Inc.
+   Copyright (C) 1996-2009 Free Software Foundation, Inc.
    Copyright (C) 1994, 1995, 1997, 1998, 1999, 2000 H. Peter Anvin
 
    This program is free software: you can redistribute it and/or modify
@@ -73,8 +73,7 @@ static const char *const ls_codes[] =
   "so", "bd", "bd", "cd", "cd", "do", "ex", "lc", "lc", "rc", "rc", "ec", "ec",
   "su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", "hl", "cl", NULL
 };
-#define array_len(Array) (sizeof (Array) / sizeof *(Array))
-verify (array_len (slack_codes) == array_len (ls_codes));
+verify (ARRAY_CARDINALITY (slack_codes) == ARRAY_CARDINALITY (ls_codes));
 
 static struct option const long_options[] =
   {
index 47273a2..9ac703c 100644 (file)
@@ -282,7 +282,7 @@ static const unsigned char wheel_tab[] =
   };
 
 #define WHEEL_START (wheel_tab + WHEEL_SIZE)
-#define WHEEL_END (wheel_tab + (sizeof wheel_tab / sizeof wheel_tab[0]))
+#define WHEEL_END (wheel_tab + ARRAY_CARDINALITY (wheel_tab))
 
 /* FIXME: comment */
 
index 795d1ed..838431c 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -1223,7 +1223,7 @@ main (int argc, char **argv)
       SIGXFSZ,
 #endif
     };
-  enum { nsigs = sizeof sig / sizeof sig[0] };
+  enum { nsigs = ARRAY_CARDINALITY (sig) };
 
 #if ! SA_NOCLDSTOP
   bool caught_sig[nsigs];
@@ -1238,8 +1238,8 @@ main (int argc, char **argv)
   initialize_exit_failure (LS_FAILURE);
   atexit (close_stdout);
 
-#define N_ENTRIES(Array) (sizeof Array / sizeof *(Array))
-  assert (N_ENTRIES (color_indicator) + 1 == N_ENTRIES (indicator_name));
+  assert (ARRAY_CARDINALITY (color_indicator) + 1
+          == ARRAY_CARDINALITY (indicator_name));
 
   exit_status = EXIT_SUCCESS;
   print_dir_name = true;
index 2dcb398..56585bd 100644 (file)
--- a/src/od.c
+++ b/src/od.c
@@ -1,5 +1,5 @@
 /* od -- dump files in octal and other formats
-   Copyright (C) 92, 1995-2008 Free Software Foundation, Inc.
+   Copyright (C) 92, 1995-2009 Free Software Foundation, Inc.
 
    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
@@ -148,8 +148,7 @@ static unsigned int const bytes_to_hex_digits[] =
 /* It'll be a while before we see integral types wider than 16 bytes,
    but if/when it happens, this check will catch it.  Without this check,
    a wider type would provoke a buffer overrun.  */
-verify (MAX_INTEGRAL_TYPE_SIZE
-       < sizeof bytes_to_hex_digits / sizeof *bytes_to_hex_digits);
+verify (MAX_INTEGRAL_TYPE_SIZE < ARRAY_CARDINALITY (bytes_to_hex_digits));
 
 /* Make sure the other arrays have the same length.  */
 verify (sizeof bytes_to_oct_digits == sizeof bytes_to_signed_dec_digits);
@@ -172,7 +171,7 @@ static const int width_bytes[] =
 
 /* Ensure that for each member of `enum size_spec' there is an
    initializer in the width_bytes array.  */
-verify (sizeof width_bytes / sizeof width_bytes[0] == N_SIZE_SPECS);
+verify (ARRAY_CARDINALITY (width_bytes) == N_SIZE_SPECS);
 
 /* Names for some non-printing characters.  */
 static char const charname[33][4] =
index f48d727..6dea2ff 100644 (file)
@@ -3104,7 +3104,7 @@ main (int argc, char **argv)
        SIGXFSZ,
 #endif
       };
-    enum { nsigs = sizeof sig / sizeof sig[0] };
+    enum { nsigs = ARRAY_CARDINALITY (sig) };
 
 #if SA_NOCLDSTOP
     struct sigaction act;