Index: head/tools/regression/lib/msun/test-cexp.c =================================================================== --- head/tools/regression/lib/msun/test-cexp.c +++ head/tools/regression/lib/msun/test-cexp.c @@ -31,6 +31,8 @@ #include __FBSDID("$FreeBSD$"); +#include + #include #include #include @@ -40,8 +42,6 @@ #include "test-utils.h" -#define N(i) (sizeof(i) / sizeof((i)[0])) - #pragma STDC FENV_ACCESS ON #pragma STDC CX_LIMITED_RANGE OFF @@ -116,7 +116,7 @@ /* cexp(x + NaNi) = NaN + NaNi and optionally raises invalid */ /* cexp(NaN + yi) = NaN + NaNi and optionally raises invalid (|y|>0) */ - for (i = 0; i < N(finites); i++) { + for (i = 0; i < nitems(finites); i++) { printf("# Run %d..\n", i); testall(CMPLXL(finites[i], NAN), CMPLXL(NAN, NAN), ALL_STD_EXCEPT & ~FE_INVALID, 0, 0); @@ -148,7 +148,7 @@ int i; /* cexp(x + inf i) = NaN + NaNi and raises invalid */ - for (i = 0; i < N(finites); i++) { + for (i = 0; i < nitems(finites); i++) { printf("# Run %d..\n", i); testall(CMPLXL(finites[i], INFINITY), CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 1); @@ -189,7 +189,7 @@ { int i; - for (i = 0; i < N(finites); i++) { + for (i = 0; i < nitems(finites); i++) { /* XXX could check exceptions more meticulously */ printf("# Run %d..\n", i); test(cexp, CMPLXL(finites[i], 0.0), @@ -212,7 +212,7 @@ { int i; - for (i = 0; i < N(finites); i++) { + for (i = 0; i < nitems(finites); i++) { printf("# Run %d..\n", i); test(cexp, CMPLXL(0.0, finites[i]), CMPLXL(cos(finites[i]), sin(finites[i])), @@ -244,7 +244,7 @@ double x, y; int i; - for (i = 0; i < N(tests); i += 4) { + for (i = 0; i < nitems(tests); i += 4) { printf("# Run %d..\n", i); a = tests[i]; b = tests[i + 1]; Index: head/tools/regression/lib/msun/test-csqrt.c =================================================================== --- head/tools/regression/lib/msun/test-csqrt.c +++ head/tools/regression/lib/msun/test-csqrt.c @@ -31,6 +31,8 @@ #include __FBSDID("$FreeBSD$"); +#include + #include #include #include @@ -39,8 +41,6 @@ #include "test-utils.h" -#define N(i) (sizeof(i) / sizeof((i)[0])) - /* * This is a test hook that can point to csqrtl(), _csqrt(), or to _csqrtf(). * The latter two convert to float or double, respectively, and test csqrtf() @@ -127,8 +127,8 @@ double x, y; int i, j; - for (i = 0; i < N(tests); i += 4) { - for (j = 0; j < N(mults); j++) { + for (i = 0; i < nitems(tests); i += 4) { + for (j = 0; j < nitems(mults); j++) { a = tests[i] * mults[j] * mults[j]; b = tests[i + 1] * mults[j] * mults[j]; x = tests[i + 2] * mults[j]; @@ -169,7 +169,7 @@ int i; - for (i = 0; i < N(vals); i++) { + for (i = 0; i < nitems(vals); i++) { if (isfinite(vals[i])) { assert_equal(t_csqrt(CMPLXL(-INFINITY, vals[i])), CMPLXL(0.0, copysignl(INFINITY, vals[i]))); Index: head/tools/regression/lib/msun/test-invtrig.c =================================================================== --- head/tools/regression/lib/msun/test-invtrig.c +++ head/tools/regression/lib/msun/test-invtrig.c @@ -41,8 +41,6 @@ #include "test-utils.h" -#define LEN(a) (sizeof(a) / sizeof((a)[0])) - #pragma STDC FENV_ACCESS ON /* Index: head/tools/regression/lib/msun/test-trig.c =================================================================== --- head/tools/regression/lib/msun/test-trig.c +++ head/tools/regression/lib/msun/test-trig.c @@ -36,6 +36,8 @@ #include __FBSDID("$FreeBSD$"); +#include + #include #include #include @@ -44,8 +46,6 @@ #include "test-utils.h" -#define LEN(a) (sizeof(a) / sizeof((a)[0])) - #pragma STDC FENV_ACCESS ON /* @@ -155,7 +155,7 @@ int i; - for (i = 0; i < LEN(f_pi_odd); i++) { + for (i = 0; i < nitems(f_pi_odd); i++) { assert(fabs(sinf(f_pi_odd[i])) < FLT_EPSILON); assert(cosf(f_pi_odd[i]) == -1.0); assert(fabs(tan(f_pi_odd[i])) < FLT_EPSILON); @@ -173,7 +173,7 @@ assert(fabs(tanf(-f_pi_odd[i] * 2)) < FLT_EPSILON); } - for (i = 0; i < LEN(d_pi_odd); i++) { + for (i = 0; i < nitems(d_pi_odd); i++) { assert(fabs(sin(d_pi_odd[i])) < 2 * DBL_EPSILON); assert(cos(d_pi_odd[i]) == -1.0); assert(fabs(tan(d_pi_odd[i])) < 2 * DBL_EPSILON); @@ -192,7 +192,7 @@ } #if LDBL_MANT_DIG > 53 - for (i = 0; i < LEN(ld_pi_odd); i++) { + for (i = 0; i < nitems(ld_pi_odd); i++) { assert(fabsl(sinl(ld_pi_odd[i])) < LDBL_EPSILON); assert(cosl(ld_pi_odd[i]) == -1.0); assert(fabsl(tanl(ld_pi_odd[i])) < LDBL_EPSILON); Index: head/tools/regression/p1003_1b/main.c =================================================================== --- head/tools/regression/p1003_1b/main.c +++ head/tools/regression/p1003_1b/main.c @@ -1,4 +1,7 @@ /* $FreeBSD$ */ + +#include + #include #include @@ -20,8 +23,6 @@ { "yield", yield, 1 }, }; -#define N(T) (sizeof (T)/ sizeof(T[0])) - static int usage(int argc, char *argv[]) { int i; @@ -47,14 +48,14 @@ " (my notes say \"because things detach\");\n" "meanwhile do these individual tests and look" " for a non-zero exit code:\n"); - for (i = 0; i < N(tab); i++) + for (i = 0; i < nitems(tab); i++) if (tab[i].works) fprintf(stderr, "p1003_1b %s\n", tab[i].t); return -1; #else { int r; - for (i = 0; i < N(tab); i++) { + for (i = 0; i < nitems(tab); i++) { if (tab[i].works) { if ( (r = (*tab[i].f)(argc - 1, argv + 1)) ) { @@ -70,7 +71,7 @@ } if (argc > 1) { - for (i = 0; i < N(tab); i++) + for (i = 0; i < nitems(tab); i++) if (strcmp(tab[i].t, argv[1]) == 0) return (*tab[i].f)(argc - 1, argv + 1); } Index: head/tools/tools/ath/athaggrstats/athaggrstats.c =================================================================== --- head/tools/tools/ath/athaggrstats/athaggrstats.c +++ head/tools/tools/ath/athaggrstats/athaggrstats.c @@ -29,6 +29,8 @@ * $FreeBSD$ */ +#include + #include "opt_ah.h" /* @@ -368,13 +370,12 @@ struct athaggrstatfoo * athaggrstats_new(const char *ifname, const char *fmtstring) { -#define N(a) (sizeof(a) / sizeof(a[0])) struct athaggrstatfoo_p *wf; wf = calloc(1, sizeof(struct athaggrstatfoo_p)); if (wf != NULL) { bsdstat_init(&wf->base.base, "athaggrstats", - athaggrstats, N(athaggrstats)); + athaggrstats, nitems(athaggrstats)); /* override base methods */ wf->base.base.collect_cur = ath_collect_cur; wf->base.base.collect_tot = ath_collect_tot; @@ -400,5 +401,4 @@ wf->base.setfmt(&wf->base, fmtstring); } return &wf->base; -#undef N } Index: head/tools/tools/ath/athaggrstats/main.c =================================================================== --- head/tools/tools/ath/athaggrstats/main.c +++ head/tools/tools/ath/athaggrstats/main.c @@ -42,12 +42,14 @@ * print a list of all possible statistics for use with the -o option. */ +#include + +#include +#include #include #include -#include -#include #include -#include +#include #include "athaggrstats.h" @@ -63,13 +65,11 @@ static const char * getfmt(const char *tag) { -#define N(a) (sizeof(a)/sizeof(a[0])) int i; - for (i = 0; i < N(tags); i++) + for (i = 0; i < nitems(tags); i++) if (strcasecmp(tags[i].tag, tag) == 0) return tags[i].fmt; return tag; -#undef N } static int signalled; Index: head/tools/tools/ath/athdebug/athdebug.c =================================================================== --- head/tools/tools/ath/athdebug/athdebug.c +++ head/tools/tools/ath/athdebug/athdebug.c @@ -33,21 +33,20 @@ * athdebug [-i interface] flags * (default interface is ath0). */ -#include + +#include #include #include #include #include -#include #include +#include #include +#include #include #include #include -#include - -#define N(a) (sizeof(a)/sizeof(a[0])) const char *progname; @@ -115,7 +114,7 @@ { int i; - for (i = 0; i < N(flags); i++) + for (i = 0; i < nitems(flags); i++) if (strncasecmp(flags[i].name, name, len) == 0) return flags[i].bit; return 0; @@ -126,7 +125,7 @@ { int i; - for (i = 0; i < N(flags); i++) + for (i = 0; i < nitems(flags); i++) if (flags[i].bit == flag) return flags[i].name; return "???"; @@ -139,7 +138,7 @@ fprintf(stderr, "usage: %s [-i device] [flags]\n", progname); fprintf(stderr, "where flags are:\n"); - for (i = 0; i < N(flags); i++) + for (i = 0; i < nitems(flags); i++) printf("%s\n", flags[i].name); exit(-1); } @@ -221,7 +220,7 @@ } else printf("%s: 0x%llx", oid, (long long) debug); sep = "<"; - for (i = 0; i < N(flags); i++) + for (i = 0; i < nitems(flags); i++) if (debug & flags[i].bit) { printf("%s%s", sep, flags[i].name); sep = ","; Index: head/tools/tools/ath/athrd/athrd.c =================================================================== --- head/tools/tools/ath/athrd/athrd.c +++ head/tools/tools/ath/athrd/athrd.c @@ -32,18 +32,20 @@ #include "ah.h" +#include + #include #include #include "ah_internal.h" #include "ah_eeprom_v3.h" /* XXX */ +#include +#include #include #include -#include #include #include -#include int ath_hal_debug = 0; HAL_CTRY_CODE cc = CTRY_DEFAULT; @@ -535,43 +537,37 @@ static HAL_BOOL rdlookup(const char *name, HAL_REG_DOMAIN *rd) { -#define N(a) (sizeof(a)/sizeof(a[0])) int i; - for (i = 0; i < N(domains); i++) + for (i = 0; i < nitems(domains); i++) if (strcasecmp(domains[i].name, name) == 0) { *rd = domains[i].rd; return AH_TRUE; } return AH_FALSE; -#undef N } static const char * getrdname(HAL_REG_DOMAIN rd) { -#define N(a) (sizeof(a)/sizeof(a[0])) int i; - for (i = 0; i < N(domains); i++) + for (i = 0; i < nitems(domains); i++) if (domains[i].rd == rd) return domains[i].name; return NULL; -#undef N } static void rdlist() { -#define N(a) (sizeof(a)/sizeof(a[0])) int i; printf("\nRegulatory domains:\n\n"); - for (i = 0; i < N(domains); i++) + for (i = 0; i < nitems(domains); i++) printf("%-15s%s", domains[i].name, ((i+1)%5) == 0 ? "\n" : ""); printf("\n"); -#undef N } typedef struct { @@ -728,10 +724,9 @@ static HAL_BOOL cclookup(const char *name, HAL_REG_DOMAIN *rd, HAL_CTRY_CODE *cc) { -#define N(a) (sizeof(a)/sizeof(a[0])) int i; - for (i = 0; i < N(allCountries); i++) + for (i = 0; i < nitems(allCountries); i++) if (strcasecmp(allCountries[i].isoName, name) == 0 || strcasecmp(allCountries[i].name, name) == 0) { *rd = allCountries[i].regDmnEnum; @@ -739,49 +734,42 @@ return AH_TRUE; } return AH_FALSE; -#undef N } static const char * getccname(HAL_CTRY_CODE cc) { -#define N(a) (sizeof(a)/sizeof(a[0])) int i; - for (i = 0; i < N(allCountries); i++) + for (i = 0; i < nitems(allCountries); i++) if (allCountries[i].countryCode == cc) return allCountries[i].name; return NULL; -#undef N } static const char * getccisoname(HAL_CTRY_CODE cc) { -#define N(a) (sizeof(a)/sizeof(a[0])) int i; - for (i = 0; i < N(allCountries); i++) + for (i = 0; i < nitems(allCountries); i++) if (allCountries[i].countryCode == cc) return allCountries[i].isoName; return NULL; -#undef N } static void cclist() { -#define N(a) (sizeof(a)/sizeof(a[0])) int i; printf("\nCountry codes:\n"); - for (i = 0; i < N(allCountries); i++) + for (i = 0; i < nitems(allCountries); i++) printf("%2s %-15.15s%s", allCountries[i].isoName, allCountries[i].name, ((i+1)%4) == 0 ? "\n" : " "); printf("\n"); -#undef N } static HAL_BOOL Index: head/tools/tools/ath/athstats/athstats.c =================================================================== --- head/tools/tools/ath/athstats/athstats.c +++ head/tools/tools/ath/athstats/athstats.c @@ -34,20 +34,22 @@ /* * ath statistics class. */ -#include + +#include #include #include #include + #include #include #include +#include +#include #include #include -#include #include #include -#include #include "ah.h" #include "ah_desc.h" @@ -1058,12 +1060,12 @@ struct athstatfoo * athstats_new(const char *ifname, const char *fmtstring) { -#define N(a) (sizeof(a) / sizeof(a[0])) struct athstatfoo_p *wf; wf = calloc(1, sizeof(struct athstatfoo_p)); if (wf != NULL) { - bsdstat_init(&wf->base.base, "athstats", athstats, N(athstats)); + bsdstat_init(&wf->base.base, "athstats", athstats, + nitems(athstats)); /* override base methods */ wf->base.base.collect_cur = ath_collect_cur; wf->base.base.collect_tot = ath_collect_tot; @@ -1089,5 +1091,4 @@ wf->base.setfmt(&wf->base, fmtstring); } return &wf->base; -#undef N } Index: head/tools/tools/ath/athstats/main.c =================================================================== --- head/tools/tools/ath/athstats/main.c +++ head/tools/tools/ath/athstats/main.c @@ -41,12 +41,14 @@ * print a list of all possible statistics for use with the -o option. */ +#include + +#include +#include #include #include -#include -#include #include -#include +#include #include "athstats.h" @@ -68,13 +70,11 @@ static const char * getfmt(const char *tag) { -#define N(a) (sizeof(a)/sizeof(a[0])) int i; - for (i = 0; i < N(tags); i++) + for (i = 0; i < nitems(tags); i++) if (strcasecmp(tags[i].tag, tag) == 0) return tags[i].fmt; return tag; -#undef N } static int signalled; Index: head/tools/tools/ath/common/ah_osdep.h =================================================================== --- head/tools/tools/ath/common/ah_osdep.h +++ head/tools/tools/ath/common/ah_osdep.h @@ -35,6 +35,8 @@ */ #include +#include + /* * Bus i/o type definitions. */ Index: head/tools/tools/ath/common/dumpregs_5210.c =================================================================== --- head/tools/tools/ath/common/dumpregs_5210.c +++ head/tools/tools/ath/common/dumpregs_5210.c @@ -28,6 +28,9 @@ * * $FreeBSD$ */ + +#include + #include "diag.h" #include "ah.h" @@ -37,8 +40,6 @@ #include "dumpregs.h" -#define N(a) (sizeof(a) / sizeof(a[0])) - static struct dumpreg ar5210regs[] = { DEFBASIC(AR_TXDP0, "TXDP0"), DEFBASIC(AR_TXDP1, "TXDP1"), @@ -118,7 +119,7 @@ ar5210_ctor(void) { #define MAC5210 SREV(1,0), SREV(2,0) - register_regs(ar5210regs, N(ar5210regs), MAC5210, PHYANY); + register_regs(ar5210regs, nitems(ar5210regs), MAC5210, PHYANY); register_keycache(64, MAC5210, PHYANY); register_range(0x9800, 0x9840, DUMP_BASEBAND, MAC5210, PHYANY); Index: head/tools/tools/ath/common/dumpregs_5211.c =================================================================== --- head/tools/tools/ath/common/dumpregs_5211.c +++ head/tools/tools/ath/common/dumpregs_5211.c @@ -28,6 +28,9 @@ * * $FreeBSD$ */ + +#include + #include "diag.h" #include "ah.h" @@ -37,8 +40,6 @@ #include "dumpregs.h" -#define N(a) (sizeof(a) / sizeof(a[0])) - static struct dumpreg ar5211regs[] = { DEFBASICfmt(AR_CR, "CR", AR_CR_BITS), DEFBASIC(AR_RXDP, "RXDP"), @@ -284,7 +285,7 @@ ar5211_ctor(void) { #define MAC5211 SREV(2,0), SREV(4,5) - register_regs(ar5211regs, N(ar5211regs), MAC5211, PHYANY); + register_regs(ar5211regs, nitems(ar5211regs), MAC5211, PHYANY); register_keycache(128, MAC5211, PHYANY); register_range(0x9800, 0x987c, DUMP_BASEBAND, MAC5211, PHYANY); Index: head/tools/tools/ath/common/dumpregs_5212.c =================================================================== --- head/tools/tools/ath/common/dumpregs_5212.c +++ head/tools/tools/ath/common/dumpregs_5212.c @@ -28,6 +28,9 @@ * * $FreeBSD$ */ + +#include + #include "diag.h" #include "ah.h" @@ -37,8 +40,6 @@ #include "dumpregs.h" -#define N(a) (sizeof(a) / sizeof(a[0])) - #define MAC5212 SREV(4,5), SREV(16,0) #define MAC5213 SREV(5,9), SREV(16,0) @@ -421,7 +422,7 @@ static __constructor void ar5212_ctor(void) { - register_regs(ar5212regs, N(ar5212regs), MAC5212, PHYANY); + register_regs(ar5212regs, nitems(ar5212regs), MAC5212, PHYANY); register_keycache(128, MAC5212, PHYANY); register_range(0x9800, 0x987c, DUMP_BASEBAND, MAC5212, PHYANY); Index: head/tools/tools/ath/common/dumpregs_5416.c =================================================================== --- head/tools/tools/ath/common/dumpregs_5416.c +++ head/tools/tools/ath/common/dumpregs_5416.c @@ -28,6 +28,9 @@ * * $FreeBSD$ */ + +#include + #include "diag.h" #include "ah.h" @@ -37,8 +40,6 @@ #include "dumpregs.h" -#define N(a) (sizeof(a) / sizeof(a[0])) - #define MAC5416 SREV(13,8), SREV(0xffff,0xffff) /* XXX */ static struct dumpreg ar5416regs[] = { @@ -406,7 +407,7 @@ static __constructor void ar5416_ctor(void) { - register_regs(ar5416regs, N(ar5416regs), MAC5416, PHYANY); + register_regs(ar5416regs, nitems(ar5416regs), MAC5416, PHYANY); register_keycache(128, MAC5416, PHYANY); register_range(0x9800, 0x987c, DUMP_BASEBAND, MAC5416, PHYANY); Index: head/tools/tools/crypto/cryptostats.c =================================================================== --- head/tools/tools/crypto/cryptostats.c +++ head/tools/tools/crypto/cryptostats.c @@ -30,15 +30,19 @@ * Little program to dump the crypto statistics block and, optionally, * zero all the stats or just the timing stuff. */ -#include -#include -#include #include #include #include + #include +#include +#include +#include +#include +#include + static void printt(const char* tag, struct cryptotstat *ts) { Index: head/tools/tools/crypto/cryptotest.c =================================================================== --- head/tools/tools/crypto/cryptotest.c +++ head/tools/tools/crypto/cryptotest.c @@ -82,25 +82,25 @@ * Expect ~400 Mb/s for a Broadcom 582x for 8K buffers on a reasonable CPU * (64-bit PCI helps). Hifn 7811 parts top out at ~110 Mb/s. */ -#include + #include -#include #include -#include -#include -#include -#include #include +#include +#include +#include + +#include +#include #include +#include #include #include +#include -#include -#include #include #define CHUNK 64 /* how much to display */ -#define N(a) (sizeof (a) / sizeof (a[0])) #define streq(a,b) (strcasecmp(a,b) == 0) void hexdump(char *, int); @@ -164,7 +164,7 @@ { int i; - for (i = 0; i < N(algorithms); i++) + for (i = 0; i < nitems(algorithms); i++) if (cipher == algorithms[i].code) return &algorithms[i]; return NULL; @@ -175,7 +175,7 @@ { int i; - for (i = 0; i < N(algorithms); i++) + for (i = 0; i < nitems(algorithms); i++) if (streq(name, algorithms[i].name)) return &algorithms[i]; return NULL; @@ -239,7 +239,7 @@ 0x10,0x54,0x11,0x48,0x45,0x12,0x4f,0x13,0x49,0x53,0x14,0x41, 0x15,0x16,0x4e,0x55,0x54,0x17,0x18,0x4a,0x4f,0x42,0x19,0x01 }; - return 0x20+a[random()%N(a)]; + return 0x20+a[random()%nitems(a)]; } static void @@ -298,7 +298,7 @@ for (i = 0; i < size; i++) cleartext[i] = rdigit(); memcpy(originaltext, cleartext, size); - for (i = 0; i < N(iv); i++) + for (i = 0; i < nitems(iv); i++) iv[i] = rdigit(); if (verbose) { @@ -569,7 +569,7 @@ count = atoi(argv[0]); while (argc > 1) { int s = atoi(argv[1]); - if (nsizes < N(sizes)) { + if (nsizes < nitems(sizes)) { sizes[nsizes++] = s; } else { printf("Too many sizes, ignoring %u\n", s); @@ -590,7 +590,7 @@ } if (testall) { - for (i = 0; i < N(algorithms); i++) { + for (i = 0; i < nitems(algorithms); i++) { int j; alg = &algorithms[i]; for (j = 0; j < nsizes; j++) Index: head/tools/tools/crypto/hifnstats.c =================================================================== --- head/tools/tools/crypto/hifnstats.c +++ head/tools/tools/crypto/hifnstats.c @@ -25,8 +25,13 @@ * * $FreeBSD$ */ -#include + #include +#include + +#include +#include + #include "../../../sys/dev/hifn/hifn7751var.h" /* @@ -39,7 +44,7 @@ size_t slen; slen = sizeof (stats); - if (sysctlbyname("hw.hifn.stats", &stats, &slen, NULL, NULL) < 0) + if (sysctlbyname("hw.hifn.stats", &stats, &slen, NULL, 0) < 0) err(1, "kern.hifn.stats"); printf("input %llu bytes %u packets\n", Index: head/tools/tools/crypto/ipsecstats.c =================================================================== --- head/tools/tools/crypto/ipsecstats.c +++ head/tools/tools/crypto/ipsecstats.c @@ -25,10 +25,15 @@ * * $FreeBSD$ */ -#include + +#include +#include + #include #include #include + +#include #include #include @@ -62,7 +67,6 @@ { SADB_X_CALG_DEFLATE, "deflate", }, { SADB_X_CALG_LZS, "lzs", }, }; -#define N(a) (sizeof(a)/sizeof(a[0])) static const char* algname(int a, const struct alg algs[], int nalgs) @@ -91,13 +95,13 @@ int i; slen = sizeof (ips); - if (sysctlbyname("net.inet.ipsec.ipsecstats", &ips, &slen, NULL, NULL) < 0) + if (sysctlbyname("net.inet.ipsec.ipsecstats", &ips, &slen, NULL, 0) < 0) err(1, "net.inet.ipsec.ipsecstats"); slen = sizeof (ahs); - if (sysctlbyname("net.inet.ah.stats", &ahs, &slen, NULL, NULL) < 0) + if (sysctlbyname("net.inet.ah.stats", &ahs, &slen, NULL, 0) < 0) err(1, "net.inet.ah.stats"); slen = sizeof (esps); - if (sysctlbyname("net.inet.esp.stats", &esps, &slen, NULL, NULL) < 0) + if (sysctlbyname("net.inet.esp.stats", &esps, &slen, NULL, 0) < 0) err(1, "net.inet.esp.stats"); #define AHSTAT(x,fmt) if (x) printf("ah " fmt ": %ju\n", (uintmax_t)x) @@ -121,7 +125,7 @@ for (i = 0; i < AH_ALG_MAX; i++) if (ahs.ahs_hist[i]) printf("ah packets with %s: %ju\n" - , algname(i, aalgs, N(aalgs)) + , algname(i, aalgs, nitems(aalgs)) , (uintmax_t)ahs.ahs_hist[i] ); AHSTAT(ahs.ahs_ibytes, "bytes received"); @@ -150,7 +154,7 @@ for (i = 0; i < ESP_ALG_MAX; i++) if (esps.esps_hist[i]) printf("esp packets with %s: %ju\n" - , algname(i, espalgs, N(espalgs)) + , algname(i, espalgs, nitems(espalgs)) , (uintmax_t)esps.esps_hist[i] ); ESPSTAT(esps.esps_ibytes, "bytes received"); Index: head/tools/tools/crypto/safestats.c =================================================================== --- head/tools/tools/crypto/safestats.c +++ head/tools/tools/crypto/safestats.c @@ -25,8 +25,13 @@ * * $FreeBSD$ */ -#include + #include +#include + +#include +#include + #include "../../../sys/dev/safe/safevar.h" /* @@ -39,7 +44,7 @@ size_t slen; slen = sizeof (stats); - if (sysctlbyname("hw.safe.stats", &stats, &slen, NULL, NULL) < 0) + if (sysctlbyname("hw.safe.stats", &stats, &slen, NULL, 0) < 0) err(1, "hw.safe.stats"); printf("input %llu bytes %u packets\n", Index: head/tools/tools/crypto/ubsecstats.c =================================================================== --- head/tools/tools/crypto/ubsecstats.c +++ head/tools/tools/crypto/ubsecstats.c @@ -25,8 +25,13 @@ * * $FreeBSD$ */ -#include + #include +#include + +#include +#include + #include "../../../sys/dev/ubsec/ubsecvar.h" /* @@ -39,7 +44,7 @@ size_t slen; slen = sizeof (stats); - if (sysctlbyname("hw.ubsec.stats", &stats, &slen, NULL, NULL) < 0) + if (sysctlbyname("hw.ubsec.stats", &stats, &slen, NULL, 0) < 0) err(1, "kern.ubsec_stats"); printf("input %llu bytes %u packets\n", Index: head/tools/tools/cxgbetool/cxgbetool.c =================================================================== --- head/tools/tools/cxgbetool/cxgbetool.c +++ head/tools/tools/cxgbetool/cxgbetool.c @@ -28,29 +28,30 @@ #include __FBSDID("$FreeBSD$"); -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include -#include #include -#include #include #include -#include -#include + #include +#include #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "t4_ioctl.h" -#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define in_range(val, lo, hi) ( val < 0 || (val <= hi && val >= lo)) #define max(x, y) ((x) > (y) ? (x) : (y)) @@ -345,7 +346,7 @@ T4_MODREGS(xgmac) }; - return dump_regs_table(argc, argv, regs, t4_mod, ARRAY_SIZE(t4_mod)); + return dump_regs_table(argc, argv, regs, t4_mod, nitems(t4_mod)); } #undef T4_MODREGS @@ -360,8 +361,7 @@ { "cim", t4vf_cim_regs }, }; - return dump_regs_table(argc, argv, regs, t4vf_mod, - ARRAY_SIZE(t4vf_mod)); + return dump_regs_table(argc, argv, regs, t4vf_mod, nitems(t4vf_mod)); } #define T5_MODREGS(name) { #name, t5_##name##_regs } @@ -398,7 +398,7 @@ { "hma", t5_hma_t5_regs } }; - return dump_regs_table(argc, argv, regs, t5_mod, ARRAY_SIZE(t5_mod)); + return dump_regs_table(argc, argv, regs, t5_mod, nitems(t5_mod)); } #undef T5_MODREGS Index: head/tools/tools/mwl/mwldebug/mwldebug.c =================================================================== --- head/tools/tools/mwl/mwldebug/mwldebug.c +++ head/tools/tools/mwl/mwldebug/mwldebug.c @@ -33,21 +33,19 @@ * mwldebug [-i interface] flags * (default interface is mwl0). */ -#include + #include #include #include #include #include -#include -#include #include +#include #include +#include +#include #include -#include - -#define N(a) (sizeof(a)/sizeof(a[0])) const char *progname; @@ -100,7 +98,7 @@ { int i; - for (i = 0; i < N(flags); i++) + for (i = 0; i < nitems(flags); i++) if (strncasecmp(flags[i].name, name, len) == 0) return flags[i].bit; return 0; @@ -112,7 +110,7 @@ { int i; - for (i = 0; i < N(flags); i++) + for (i = 0; i < nitems(flags); i++) if (flags[i].bit == flag) return flags[i].name; return "???"; @@ -126,7 +124,7 @@ fprintf(stderr, "usage: %s [-i device] [flags]\n", progname); fprintf(stderr, "where flags are:\n"); - for (i = 0; i < N(flags); i++) + for (i = 0; i < nitems(flags); i++) printf("%s\n", flags[i].name); exit(-1); } @@ -202,7 +200,7 @@ } else printf("%s: 0x%x", oid, debug); sep = "<"; - for (i = 0; i < N(flags); i++) + for (i = 0; i < nitems(flags); i++) if (debug & flags[i].bit) { printf("%s%s", sep, flags[i].name); sep = ","; Index: head/tools/tools/mwl/mwlstats/mwlstats.c =================================================================== --- head/tools/tools/mwl/mwlstats/mwlstats.c +++ head/tools/tools/mwl/mwlstats/mwlstats.c @@ -32,20 +32,22 @@ /* * mwl statistics class. */ -#include + +#include #include +#include #include #include -#include + #include #include -#include -#include +#include #include +#include +#include #include #include -#include #include "../../../../sys/net80211/ieee80211_ioctl.h" #include "../../../../sys/net80211/ieee80211_radiotap.h" @@ -544,12 +546,12 @@ struct mwlstatfoo * mwlstats_new(const char *ifname, const char *fmtstring) { -#define N(a) (sizeof(a) / sizeof(a[0])) struct mwlstatfoo_p *wf; wf = calloc(1, sizeof(struct mwlstatfoo_p)); if (wf != NULL) { - bsdstat_init(&wf->base.base, "mwlstats", mwlstats, N(mwlstats)); + bsdstat_init(&wf->base.base, "mwlstats", mwlstats, + nitems(mwlstats)); /* override base methods */ wf->base.base.collect_cur = mwl_collect_cur; wf->base.base.collect_tot = mwl_collect_tot; @@ -574,5 +576,4 @@ wf->base.setfmt(&wf->base, fmtstring); } return &wf->base; -#undef N } Index: head/tools/tools/net80211/wlanstats/main.c =================================================================== --- head/tools/tools/net80211/wlanstats/main.c +++ head/tools/tools/net80211/wlanstats/main.c @@ -34,17 +34,18 @@ * (default interface is wlan0). */ -#include +#include #include + #include #include -#include -#include -#include -#include #include +#include +#include +#include #include +#include #include "wlanstats.h" @@ -65,13 +66,11 @@ static const char * getfmt(const char *tag) { -#define N(a) (sizeof(a)/sizeof(a[0])) int i; - for (i = 0; i < N(tags); i++) + for (i = 0; i < nitems(tags); i++) if (strcasecmp(tags[i].tag, tag) == 0) return tags[i].fmt; return tag; -#undef N } static int signalled; Index: head/tools/tools/net80211/wlanstats/wlanstats.c =================================================================== --- head/tools/tools/net80211/wlanstats/wlanstats.c +++ head/tools/tools/net80211/wlanstats/wlanstats.c @@ -32,23 +32,25 @@ /* * net80211 statistics class. */ -#include + +#include #include #include #include + #include #include #include #include #include +#include +#include +#include #include #include -#include #include #include -#include -#include #include "../../../../sys/net80211/ieee80211_ioctl.h" @@ -558,7 +560,6 @@ void setreason(char b[], size_t bs, int v) { -#define N(a) (sizeof(a)/sizeof(a[0])) static const char *reasons[] = { [IEEE80211_REASON_UNSPECIFIED] = "unspecified", [IEEE80211_REASON_AUTH_EXPIRE] = "auth expire", @@ -584,17 +585,15 @@ [IEEE80211_REASON_802_1X_AUTH_FAILED] = "802.1x auth failed", [IEEE80211_REASON_CIPHER_SUITE_REJECTED]= "cipher suite rejected", }; - if (v < N(reasons) && reasons[v] != NULL) + if (v < nitems(reasons) && reasons[v] != NULL) snprintf(b, bs, "%s (%u)", reasons[v], v); else snprintf(b, bs, "%u", v); -#undef N } void setstatus(char b[], size_t bs, int v) { -#define N(a) (sizeof(a)/sizeof(a[0])) static const char *status[] = { [IEEE80211_STATUS_SUCCESS] = "success", [IEEE80211_STATUS_UNSPECIFIED] = "unspecified", @@ -623,11 +622,10 @@ [IEEE80211_STATUS_INVALID_RSN_IE_CAP] = "invalid rsn ie cap", [IEEE80211_STATUS_CIPHER_SUITE_REJECTED]= "cipher suite rejected", }; - if (v < N(status) && status[v] != NULL) + if (v < nitems(status) && status[v] != NULL) snprintf(b, bs, "%s (%u)", status[v], v); else snprintf(b, bs, "%u", v); -#undef N } static int @@ -999,12 +997,12 @@ struct wlanstatfoo * wlanstats_new(const char *ifname, const char *fmtstring) { -#define N(a) (sizeof(a) / sizeof(a[0])) struct wlanstatfoo_p *wf; wf = calloc(1, sizeof(struct wlanstatfoo_p)); if (wf != NULL) { - bsdstat_init(&wf->base.base, "wlanstats", wlanstats, N(wlanstats)); + bsdstat_init(&wf->base.base, "wlanstats", wlanstats, + nitems(wlanstats)); /* override base methods */ wf->base.base.collect_cur = wlan_collect_cur; wf->base.base.collect_tot = wlan_collect_tot; @@ -1030,5 +1028,4 @@ wf->base.setfmt(&wf->base, fmtstring); } return &wf->base; -#undef N } Index: head/tools/tools/net80211/wlantxtime/wlantxtime.c =================================================================== --- head/tools/tools/net80211/wlantxtime/wlantxtime.c +++ head/tools/tools/net80211/wlantxtime/wlantxtime.c @@ -31,7 +31,6 @@ */ #include -#include #include @@ -228,13 +227,12 @@ static void ieee80211_setup_ratetable(struct ieee80211_rate_table *rt) { -#define N(a) (sizeof(a)/sizeof(a[0])) #define WLAN_CTRL_FRAME_SIZE \ (sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN) int i; - for (i = 0; i < N(rt->rateCodeToIndex); i++) + for (i = 0; i < nitems(rt->rateCodeToIndex); i++) rt->rateCodeToIndex[i] = (uint8_t) -1; for (i = 0; i < rt->rateCount; i++) { uint8_t code = rt->info[i].dot11Rate; @@ -267,14 +265,12 @@ } #undef WLAN_CTRL_FRAME_SIZE -#undef N } /* Setup all rate tables */ static void ieee80211_phy_init(void) { -#define N(arr) (int)(sizeof(arr) / sizeof(arr[0])) static struct ieee80211_rate_table * const ratetables[] = { &ieee80211_half_table, &ieee80211_quarter_table, @@ -287,12 +283,11 @@ &ieee80211_11g_table, &ieee80211_11b_table }; - int i; + unsigned int i; - for (i = 0; i < N(ratetables); ++i) + for (i = 0; i < nitems(ratetables); ++i) ieee80211_setup_ratetable(ratetables[i]); -#undef N } #define CCK_SIFS_TIME 10 #define CCK_PREAMBLE_BITS 144 Index: head/tools/tools/npe/npestats/main.c =================================================================== --- head/tools/tools/npe/npestats/main.c +++ head/tools/tools/npe/npestats/main.c @@ -29,12 +29,14 @@ * $FreeBSD$ */ +#include + +#include +#include #include #include -#include #include #include -#include #include "npestats.h" @@ -50,13 +52,11 @@ static const char * getfmt(const char *tag) { -#define N(a) (sizeof(a)/sizeof(a[0])) int i; - for (i = 0; i < N(tags); i++) + for (i = 0; i < nitems(tags); i++) if (strcasecmp(tags[i].tag, tag) == 0) return tags[i].fmt; return tag; -#undef N } static int signalled; Index: head/tools/tools/npe/npestats/npestats.c =================================================================== --- head/tools/tools/npe/npestats/npestats.c +++ head/tools/tools/npe/npestats/npestats.c @@ -32,15 +32,15 @@ /* * npe statistics class. */ -#include +#include #include +#include +#include #include #include -#include #include #include -#include #include "npestats.h" @@ -251,12 +251,12 @@ struct npestatfoo * npestats_new(const char *ifname, const char *fmtstring) { -#define N(a) (sizeof(a) / sizeof(a[0])) struct npestatfoo_p *wf; wf = calloc(1, sizeof(struct npestatfoo_p)); if (wf != NULL) { - bsdstat_init(&wf->base.base, "npestats", npestats, N(npestats)); + bsdstat_init(&wf->base.base, "npestats", npestats, + nitems(npestats)); /* override base methods */ wf->base.base.collect_cur = npe_collect_cur; wf->base.base.collect_tot = npe_collect_tot; @@ -274,5 +274,4 @@ wf->base.setfmt(&wf->base, fmtstring); } return &wf->base; -#undef N }