From 837d16ccbe0fca413f8927da6a34b1e97ccada8a Mon Sep 17 00:00:00 2001 From: "Balaji.G" Date: Wed, 26 Sep 2012 14:09:10 +0530 Subject: *: 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 Signed-off-by: David Lamparter --- lib/log.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'lib/log.c') 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