diff options
author | Balaji.G <balajig81@gmail.com> | 2012-09-26 14:09:10 +0530 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2012-10-25 10:15:59 -0700 |
commit | 837d16ccbe0fca413f8927da6a34b1e97ccada8a (patch) | |
tree | 7aed5a517b619c03d11bf567f6a14cda6f8f5efe /lib/log.c | |
parent | 655071f44aab42e89bcece3a93da456fdd0d913a (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/log.c')
-rw-r--r-- | lib/log.c | 24 |
1 files changed, 10 insertions, 14 deletions
@@ -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) { |