*: use array_size() helper macro

Use the array_size() helper macro.  Replaces several instances of local
macros with the same definition.

Reviewed-by: Scott Feldman <sfeldma@cumulusnetworks.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/babeld/babel_main.c b/babeld/babel_main.c
index 2f3b555..7b1d879 100644
--- a/babeld/babel_main.c
+++ b/babeld/babel_main.c
@@ -444,7 +444,7 @@
         },
     };
 
-    signal_init (master, Q_SIGC(babel_signals), babel_signals);
+    signal_init (master, array_size(babel_signals), babel_signals);
 }
 
 static void
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 2d82acc..cdc99ab 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -62,7 +62,7 @@
   { BGP_ATTR_AS4_AGGREGATOR,   "AS4_AGGREGATOR" }, 
   { BGP_ATTR_AS_PATHLIMIT,     "AS_PATHLIMIT" },
 };
-static const int attr_str_max = sizeof(attr_str)/sizeof(attr_str[0]);
+static const int attr_str_max = array_size(attr_str);
 
 static const struct message attr_flag_str[] =
 {
@@ -72,8 +72,7 @@
   /* bgp_attr_flags_diagnose() relies on this bit being last in this list */
   { BGP_ATTR_FLAG_EXTLEN,   "Extended Length" },
 };
-static const size_t attr_flag_str_max =
-  sizeof (attr_flag_str) / sizeof (attr_flag_str[0]);
+static const size_t attr_flag_str_max = array_size(attr_flag_str);
 
 static struct hash *cluster_hash;
 
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index 0f1d482..1ff1ac9 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -135,7 +135,7 @@
   .vty_group = VTY_GROUP,
 #endif
   .caps_p = _caps_p,
-  .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]),
+  .cap_num_p = array_size(_caps_p),
   .cap_num_i = 0,
 };
 
@@ -422,7 +422,7 @@
 
   /* Initializations. */
   srand (time (NULL));
-  signal_init (master, Q_SIGC(bgp_signals), bgp_signals);
+  signal_init (master, array_size(bgp_signals), bgp_signals);
   zprivs_init (&bgpd_privs);
   cmd_init (1);
   vty_init (master);
diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c
index 0326d01..d045dde 100644
--- a/bgpd/bgp_open.c
+++ b/bgpd/bgp_open.c
@@ -187,8 +187,7 @@
   { ORF_TYPE_PREFIX,		"Prefixlist"		},
   { ORF_TYPE_PREFIX_OLD,	"Prefixlist (old)"	},
 };
-static const int orf_type_str_max
-	= sizeof(orf_type_str)/sizeof(orf_type_str[0]);
+static const int orf_type_str_max = array_size(orf_type_str);
 
 static const struct message orf_mode_str[] =
 {
@@ -196,8 +195,7 @@
   { ORF_MODE_SEND,	"Send"		},
   { ORF_MODE_BOTH,	"Both"		},
 };
-static const int orf_mode_str_max
-	 = sizeof(orf_mode_str)/sizeof(orf_mode_str[0]);
+static const int orf_mode_str_max = array_size(orf_mode_str);
 
 static int
 bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr)
@@ -449,7 +447,7 @@
   { CAPABILITY_CODE_REFRESH_OLD,	"Route Refresh (Old)"		},
   { CAPABILITY_CODE_ORF_OLD,		"ORF (Old)"			},
 };
-static const int capcode_str_max = sizeof(capcode_str)/sizeof(capcode_str[0]);
+static const int capcode_str_max = array_size(capcode_str);
 
 /* Minimum sizes for length field of each cap (so not inc. the header) */
 static const size_t cap_minsizes[] = 
diff --git a/isisd/isis_main.c b/isisd/isis_main.c
index f5266aa..dcbc3de 100644
--- a/isisd/isis_main.c
+++ b/isisd/isis_main.c
@@ -325,7 +325,7 @@
    *  initializations
    */
   zprivs_init (&isisd_privs);
-  signal_init (master, Q_SIGC (isisd_signals), isisd_signals);
+  signal_init (master, array_size (isisd_signals), isisd_signals);
   cmd_init (1);
   vty_init (master);
   memory_init ();
diff --git a/lib/buffer.c b/lib/buffer.c
index f19a9e0..45e2e1c 100644
--- a/lib/buffer.c
+++ b/lib/buffer.c
@@ -262,7 +262,7 @@
   /* For erase and more data add two to b's buffer_data count.*/
   if (b->head->next == NULL)
     {
-      iov_alloc = sizeof(small_iov)/sizeof(small_iov[0]);
+      iov_alloc = array_size(small_iov);
       iov = small_iov;
     }
   else
diff --git a/lib/log.c b/lib/log.c
index cbc935b..e4ec7c2 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -443,8 +443,8 @@
 #define LOC s,buf+sizeof(buf)-s
 
 #ifdef HAVE_GLIBC_BACKTRACE
-  if (((size = backtrace(array,sizeof(array)/sizeof(array[0]))) <= 0) ||
-      ((size_t)size > sizeof(array)/sizeof(array[0])))
+  if (((size = backtrace(array,array_size(array)) <= 0) ||
+      ((size_t)size > array_size(array))))
     return;
 
 #define DUMP(FD) { \
@@ -526,12 +526,12 @@
   int size, i;
   char **strings;
 
-  if (((size = backtrace(array,sizeof(array)/sizeof(array[0]))) <= 0) ||
-      ((size_t)size > sizeof(array)/sizeof(array[0])))
+  if (((size = backtrace(array,array_size(array))) <= 0) ||
+      ((size_t)size > array_size(array)))
     {
       zlog_err("Cannot get backtrace, returned invalid # of frames %d "
 	       "(valid range is between 1 and %lu)",
-	       size, (unsigned long)(sizeof(array)/sizeof(array[0])));
+	       size, (unsigned long)(array_size(array)));
       return;
     }
   zlog(NULL, priority, "Backtrace for %d stack frames:", size);
@@ -636,7 +636,7 @@
   zl->syslog_options = syslog_flags;
 
   /* Set default logging levels. */
-  for (i = 0; i < sizeof(zl->maxlvl)/sizeof(zl->maxlvl[0]); i++)
+  for (i = 0; i < array_size(zl->maxlvl); i++)
     zl->maxlvl[i] = ZLOG_DISABLED;
   zl->maxlvl[ZLOG_DEST_MONITOR] = LOG_DEBUG;
   zl->default_lvl = LOG_DEBUG;
@@ -855,14 +855,14 @@
 {
   u_int i;
 
-  if (zroute >= sizeof(route_types)/sizeof(route_types[0]))
+  if (zroute >= array_size(route_types))
     {
       zlog_err("unknown zebra route type: %u", zroute);
       return &unknown;
     }
   if (zroute == route_types[zroute].type)
     return &route_types[zroute];
-  for (i = 0; i < sizeof(route_types)/sizeof(route_types[0]); i++)
+  for (i = 0; i < array_size(route_types); i++)
     {
       if (zroute == route_types[i].type)
         {
@@ -890,7 +890,7 @@
 const char *
 zserv_command_string (unsigned int command)
 {
-  if (command >= sizeof(command_types)/sizeof(command_types[0]))
+  if (command >= array_size(command_types))
     {
       zlog_err ("unknown zserv command type: %u", command);
       return unknown.string;
@@ -898,21 +898,17 @@
   return command_types[command].string;
 }
 
-#define RTSIZE	(sizeof(route_types)/sizeof(route_types[0]))
-
 int
 proto_name2num(const char *s)
 {
    unsigned i;
 
-   for (i=0; i<RTSIZE; ++i)
+   for (i=0; i<array_size(route_types); ++i)
      if (strcasecmp(s, route_types[i].string) == 0)
        return route_types[i].type;
    return -1;
 }
 
-#undef RTSIZE
-
 int
 proto_redistnum(int afi, const char *s)
 {
diff --git a/lib/sigevent.c b/lib/sigevent.c
index 30e9a3d..7d08fd9 100644
--- a/lib/sigevent.c
+++ b/lib/sigevent.c
@@ -22,6 +22,7 @@
 #include <zebra.h>
 #include <sigevent.h>
 #include <log.h>
+#include <memory.h>
 
 #ifdef SA_SIGINFO
 #ifdef HAVE_UCONTEXT_H
@@ -266,13 +267,13 @@
 #endif
 		   );
   } sigmap[] = {
-    { core_signals, sizeof(core_signals)/sizeof(core_signals[0]), core_handler},
-    { exit_signals, sizeof(exit_signals)/sizeof(exit_signals[0]), exit_handler},
-    { ignore_signals, sizeof(ignore_signals)/sizeof(ignore_signals[0]), NULL},
+    { core_signals, array_size(core_signals), core_handler},
+    { exit_signals, array_size(exit_signals), exit_handler},
+    { ignore_signals, array_size(ignore_signals), NULL},
   };
   u_int i;
 
-  for (i = 0; i < sizeof(sigmap)/sizeof(sigmap[0]); i++)
+  for (i = 0; i < array_size(sigmap); i++)
     {
       u_int j;
 
diff --git a/lib/sigevent.h b/lib/sigevent.h
index 62b944a..248fa2c 100644
--- a/lib/sigevent.h
+++ b/lib/sigevent.h
@@ -27,7 +27,6 @@
 #include <thread.h>
 
 #define QUAGGA_SIGNAL_TIMER_INTERVAL 2L
-#define Q_SIGC(sig) (sizeof(sig)/sizeof(sig[0]))
 
 struct quagga_signal_t
 {
diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c
index d3ef0a6..1bdf52f 100644
--- a/ospf6d/ospf6_main.c
+++ b/ospf6d/ospf6_main.c
@@ -308,7 +308,7 @@
                            LOG_DAEMON);
   zprivs_init (&ospf6d_privs);
   /* initialize zebra libraries */
-  signal_init (master, Q_SIGC(ospf6_signals), ospf6_signals);
+  signal_init (master, array_size(ospf6_signals), ospf6_signals);
   cmd_init (1);
   vty_init (master);
   memory_init ();
diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c
index 01d6126..5edb70c 100644
--- a/ospf6d/ospf6_message.c
+++ b/ospf6d/ospf6_message.c
@@ -58,8 +58,7 @@
   { OSPF6_MESSAGE_TYPE_LSUPDATE, "LSUpdate" },
   { OSPF6_MESSAGE_TYPE_LSACK,    "LSAck"    },
 };
-static const size_t ospf6_message_type_str_max =
-  sizeof (ospf6_message_type_str) / sizeof (ospf6_message_type_str[0]);
+static const size_t ospf6_message_type_str_max = array_size(ospf6_message_type_str);
 
 /* Minimum (besides the standard OSPF packet header) lengths for OSPF
    packets of particular types, offset is the "type" field. */
diff --git a/ospfd/ospf_api.c b/ospfd/ospf_api.c
index fc3b51d..74a49e3 100644
--- a/ospfd/ospf_api.c
+++ b/ospfd/ospf_api.c
@@ -155,7 +155,7 @@
     { MSG_NSM_CHANGE,            "NSM change",             },
   };
 
-  int i, n = sizeof (NameTab) / sizeof (NameTab[0]);
+  int i, n = array_size(NameTab);
   const char *name = NULL;
 
   for (i = 0; i < n; i++)
@@ -187,7 +187,7 @@
     { OSPF_API_UNDEF,                   "Undefined",                  },
   };
 
-  int i, n = sizeof (NameTab) / sizeof (NameTab[0]);
+  int i, n = array_size(NameTab);
   const char *name = NULL;
 
   for (i = 0; i < n; i++)
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index bad674b..1448c7d 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -68,7 +68,7 @@
   .vty_group = VTY_GROUP,
 #endif
   .caps_p = _caps_p,
-  .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]),
+  .cap_num_p = array_size(_caps_p),
   .cap_num_i = 0
 };
 
@@ -285,7 +285,7 @@
 
   /* Library inits. */
   zprivs_init (&ospfd_privs);
-  signal_init (master, Q_SIGC(ospf_signals), ospf_signals);
+  signal_init (master, array_size(ospf_signals), ospf_signals);
   cmd_init (1);
   debug_init ();
   vty_init (master);
diff --git a/ripd/rip_main.c b/ripd/rip_main.c
index ccb5fa0..6a9fa71 100644
--- a/ripd/rip_main.c
+++ b/ripd/rip_main.c
@@ -275,7 +275,7 @@
 
   /* Library initialization. */
   zprivs_init (&ripd_privs);
-  signal_init (master, Q_SIGC(ripd_signals), ripd_signals);
+  signal_init (master, array_size(ripd_signals), ripd_signals);
   cmd_init (1);
   vty_init (master);
   memory_init ();
diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c
index f4a6244..20225b7 100644
--- a/ripngd/ripng_main.c
+++ b/ripngd/ripng_main.c
@@ -272,7 +272,7 @@
 
   /* Library inits. */
   zprivs_init (&ripngd_privs);
-  signal_init (master, Q_SIGC(ripng_signals), ripng_signals);
+  signal_init (master, array_size(ripng_signals), ripng_signals);
   cmd_init (1);
   vty_init (master);
   memory_init ();
diff --git a/tests/test-sig.c b/tests/test-sig.c
index 63aab6f..fe428de 100644
--- a/tests/test-sig.c
+++ b/tests/test-sig.c
@@ -43,7 +43,7 @@
 main (void)
 {
   master = thread_master_create ();
-  signal_init (master, Q_SIGC(sigs), sigs);
+  signal_init (master, array_size(sigs), sigs);
   
   zlog_default = openzlog("testsig", ZLOG_NONE,
                           LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index 431c08e..e3709e0 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -61,7 +61,6 @@
   { .fd = -1, .name = "babeld", .flag = VTYSH_BABELD, .path = BABEL_VTYSH_PATH},
 };
 
-#define VTYSH_INDEX_MAX (sizeof(vtysh_client)/sizeof(vtysh_client[0]))
 
 /* We need direct access to ripd to implement vtysh_exit_ripd_only. */
 static struct vtysh_client *ripd_client = NULL;
@@ -374,7 +373,7 @@
 
 	if (! strcmp(cmd->string,"configure terminal"))
 	  {
-	    for (i = 0; i < VTYSH_INDEX_MAX; i++)
+	    for (i = 0; i < array_size(vtysh_client); i++)
 	      {
 	        cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
 		if (cmd_stat == CMD_WARNING)
@@ -413,7 +412,7 @@
 	  }
 
 	cmd_stat = CMD_SUCCESS;
-	for (i = 0; i < VTYSH_INDEX_MAX; i++)
+	for (i = 0; i < array_size(vtysh_client); i++)
 	  {
 	    if (cmd->daemon & vtysh_client[i].flag)
 	      {
@@ -525,7 +524,7 @@
 	    u_int i;
 	    int cmd_stat = CMD_SUCCESS;
 
-	    for (i = 0; i < VTYSH_INDEX_MAX; i++)
+	    for (i = 0; i < array_size(vtysh_client); i++)
 	      {
 	        if (cmd->daemon & vtysh_client[i].flag)
 		  {
@@ -1354,7 +1353,7 @@
   int ret = CMD_SUCCESS;
   char line[] = "show memory\n";
   
-  for (i = 0; i < VTYSH_INDEX_MAX; i++)
+  for (i = 0; i < array_size(vtysh_client); i++)
     if ( vtysh_client[i].fd >= 0 )
       {
         fprintf (stdout, "Memory statistics for %s:\n", 
@@ -1377,7 +1376,7 @@
   int ret = CMD_SUCCESS;
   char line[] = "show logging\n";
   
-  for (i = 0; i < VTYSH_INDEX_MAX; i++)
+  for (i = 0; i < array_size(vtysh_client); i++)
     if ( vtysh_client[i].fd >= 0 )
       {
         fprintf (stdout,"Logging configuration for %s:\n", 
@@ -1733,7 +1732,7 @@
 	   VTY_NEWLINE);
   vty_out (vty, "!%s", VTY_NEWLINE);
 
-  for (i = 0; i < VTYSH_INDEX_MAX; i++)
+  for (i = 0; i < array_size(vtysh_client); i++)
     ret = vtysh_client_config (&vtysh_client[i], line);
 
   /* Integrate vtysh specific configuration. */
@@ -1807,7 +1806,7 @@
       return CMD_SUCCESS;
     }
 
-  for (i = 0; i < VTYSH_INDEX_MAX; i++)
+  for (i = 0; i < array_size(vtysh_client); i++)
     ret = vtysh_client_config (&vtysh_client[i], line);
 
   vtysh_config_dump (fp);
@@ -1844,7 +1843,7 @@
 
   fprintf (stdout,"Building Configuration...\n");
 	  
-  for (i = 0; i < VTYSH_INDEX_MAX; i++)
+  for (i = 0; i < array_size(vtysh_client); i++)
     ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
   
   fprintf (stdout,"[OK]\n");
@@ -1934,7 +1933,7 @@
 {
   u_int i;
 
-  for (i = 0; i < VTYSH_INDEX_MAX; i++)
+  for (i = 0; i < array_size(vtysh_client); i++)
     if ( vtysh_client[i].fd >= 0 )
       vty_out(vty, " %s", vtysh_client[i].name);
   vty_out(vty, "%s", VTY_NEWLINE);
@@ -2184,7 +2183,7 @@
   int rc = 0;
   int matches = 0;
 
-  for (i = 0; i < VTYSH_INDEX_MAX; i++)
+  for (i = 0; i < array_size(vtysh_client); i++)
     {
       if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
 	{
diff --git a/watchquagga/watchquagga.c b/watchquagga/watchquagga.c
index b57fd3a..c1c8892 100644
--- a/watchquagga/watchquagga.c
+++ b/watchquagga/watchquagga.c
@@ -27,6 +27,7 @@
 #include <getopt.h>
 #include <sys/un.h>
 #include <sys/wait.h>
+#include <memory.h>
 
 #ifndef MIN
 #define MIN(X,Y) (((X) <= (Y)) ? (X) : (Y))
@@ -1279,7 +1280,7 @@
       
   gs.restart.interval = gs.min_restart_interval;
   master = thread_master_create();
-  signal_init (master, Q_SIGC(my_signals), my_signals);
+  signal_init (master, array_size(my_signals), my_signals);
   srandom(time(NULL));
 
   {
diff --git a/zebra/main.c b/zebra/main.c
index 5b5265f..50ac224 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -104,7 +104,7 @@
   .vty_group = VTY_GROUP,
 #endif
   .caps_p = _caps_p,
-  .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]),
+  .cap_num_p = array_size(_caps_p),
   .cap_num_i = 0
 };
 
@@ -313,7 +313,7 @@
   zprivs_init (&zserv_privs);
 
   /* Vty related initialize. */
-  signal_init (zebrad.master, Q_SIGC(zebra_signals), zebra_signals);
+  signal_init (zebrad.master, array_size(zebra_signals), zebra_signals);
   cmd_init (1);
   vty_init (zebrad.master);
   memory_init ();
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index 15475e2..ab28ad2 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -1985,7 +1985,7 @@
   };
 
   struct sock_fprog prog = {
-    .len = sizeof(filter) / sizeof(filter[0]),
+    .len = array_size(filter),
     .filter = filter,
   };
 
diff --git a/zebra/test_main.c b/zebra/test_main.c
index 70a1a3a..a951863 100644
--- a/zebra/test_main.c
+++ b/zebra/test_main.c
@@ -280,7 +280,7 @@
   zebrad.master = thread_master_create ();
 
   /* Vty related initialize. */
-  signal_init (zebrad.master, Q_SIGC(zebra_signals), zebra_signals);
+  signal_init (zebrad.master, array_size(zebra_signals), zebra_signals);
   cmd_init (1);
   vty_init (zebrad.master);
   memory_init ();
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index b8a4703..0e29e61 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -1546,7 +1546,7 @@
   /* Set default distance by route type. */
   if (distance == 0)
     {
-      if ((unsigned)type >= sizeof(route_info) / sizeof(route_info[0]))
+      if ((unsigned)type >= array_size(route_info))
 	distance = 150;
       else
         distance = route_info[type].distance;