diff options
author | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2012-10-10 17:54:46 +0900 |
---|---|---|
committer | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2012-10-11 14:24:07 +0900 |
commit | 9a2a26648b063ddba59e7f0e0118d0aa88ca1ace (patch) | |
tree | e8e70ae0c9d6774ec6f6f8f2e36bcce7c92f71bf /ninfod | |
parent | c8f2f41b1faeb99cb145507567bc7c84092dd17c (diff) | |
download | iputils-9a2a26648b063ddba59e7f0e0118d0aa88ca1ace.tar.gz |
ninfod: Introduce ARRAY_SIZE macro for counting number of elements in an array.
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Diffstat (limited to 'ninfod')
-rw-r--r-- | ninfod/ninfod_core.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/ninfod/ninfod_core.c b/ninfod/ninfod_core.c index 77be9d9..5cc4f9f 100644 --- a/ninfod/ninfod_core.c +++ b/ninfod/ninfod_core.c @@ -112,6 +112,8 @@ # define offsetof(aggregate,member) ((size_t)&((aggregate *)0)->member) #endif +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) + /* ---------- */ /* ID */ static char *RCSID __attribute__ ((unused)) = "$USAGI: ninfod_core.c,v 1.29 2003-07-16 09:49:01 yoshfuji Exp $"; @@ -162,7 +164,7 @@ static struct subjinfo subjinfo_null = { static __inline__ struct subjinfo *subjinfo_lookup(int code) { - if (code >= sizeof(subjinfo_table)/sizeof(subjinfo_table[0])) + if (code >= ARRAY_SIZE(subjinfo_table)) return NULL; if (subjinfo_table[code].name == NULL) return NULL; @@ -228,7 +230,7 @@ static struct qtypeinfo qtypeinfo_refused = { static __inline__ struct qtypeinfo *qtypeinfo_lookup(int qtype) { - if (qtype >= sizeof(qtypeinfo_table)/sizeof(qtypeinfo_table[0])) + if (qtype >= ARRAY_SIZE(qtypeinfo_table)) return &qtypeinfo_unknown; if (qtypeinfo_table[qtype].name == NULL) return &qtypeinfo_unknown; @@ -308,7 +310,7 @@ void init_nodeinfo_suptypes(INIT_ARGS) memset(suptypes, 0, sizeof(suptypes)); suptypes_len = 0; - for (i=0; i<sizeof(qtypeinfo_table)/sizeof(qtypeinfo_table[0]); i++) { + for (i=0; i < ARRAY_SIZE(qtypeinfo_table); i++) { unsigned short qtype; if (qtypeinfo_table[i].name == NULL) @@ -316,7 +318,7 @@ void init_nodeinfo_suptypes(INIT_ARGS) qtype = qtypeinfo_table[i].qtype; w = qtype>>5; b = qtype&0x1f; - if (w >= sizeof(suptypes)/sizeof(suptypes[0])) { + if (w > ARRAY_SIZE(suptypes)) { /* This is programming error. */ DEBUG(LOG_ERR, "Warning: Too Large Supported Types\n"); exit(1); @@ -399,14 +401,14 @@ void init_core(int forced) #endif } - for (i=0; i<sizeof(subjinfo_table)/sizeof(subjinfo_table[0]); i++) { + for (i=0; i < ARRAY_SIZE(subjinfo_table); i++) { if (subjinfo_table[i].name == NULL) continue; if (subjinfo_table[i].init) subjinfo_table[i].init(forced); } - for (i=0; i<sizeof(qtypeinfo_table)/sizeof(qtypeinfo_table[0]); i++) { + for (i=0; i < ARRAY_SIZE(qtypeinfo_table); i++) { if (qtypeinfo_table[i].name == NULL) continue; if (qtypeinfo_table[i].init) |