summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBalaji.G <balajig81@gmail.com>2012-09-26 14:09:10 +0530
committerDavid Lamparter <equinox@opensourcerouting.org>2012-10-25 10:15:59 -0700
commit837d16ccbe0fca413f8927da6a34b1e97ccada8a (patch)
tree7aed5a517b619c03d11bf567f6a14cda6f8f5efe /lib
parent655071f44aab42e89bcece3a93da456fdd0d913a (diff)
*: 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>
Diffstat (limited to 'lib')
-rw-r--r--lib/buffer.c2
-rw-r--r--lib/log.c24
-rw-r--r--lib/sigevent.c9
-rw-r--r--lib/sigevent.h1
4 files changed, 16 insertions, 20 deletions
diff --git a/lib/buffer.c b/lib/buffer.c
index f19a9e0c..45e2e1c5 100644
--- a/lib/buffer.c
+++ b/lib/buffer.c
@@ -262,7 +262,7 @@ buffer_flush_window (struct buffer *b, int fd, int width, int height,
/* 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 cbc935b6..e4ec7c22 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -443,8 +443,8 @@ zlog_backtrace_sigsafe(int priority, void *program_counter)
#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 @@ zlog_backtrace(int priority)
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 @@ openzlog (const char *progname, zlog_proto_t protocol,
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 @@ zroute_lookup(u_int zroute)
{
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 @@ zebra_route_char(u_int zroute)
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 @@ zserv_command_string (unsigned int command)
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 30e9a3d1..7d08fd97 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 @@ trap_default_signals(void)
#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 62b944a7..248fa2c0 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
{