From 70675b404ccd0af1d0d58777ebfa1f53787529dd Mon Sep 17 00:00:00 2001 From: Eitan Adler Date: Fri, 16 Feb 2018 00:53:39 -0800 Subject: [PATCH] Convert from __arysize to NELEM Try to use a single macro across the board Discussed-with: zrj, swildner --- games/colorbars/colorbars.c | 6 ++++-- sbin/init/init.c | 5 +++-- sys/cpu/x86_64/include/stdint.h | 2 -- sys/sys/param.h | 2 +- usr.bin/c89/c89.c | 4 +++- usr.bin/vmstat/vmstat.c | 3 ++- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/games/colorbars/colorbars.c b/games/colorbars/colorbars.c index b9823b0bdd..f9d9858170 100644 --- a/games/colorbars/colorbars.c +++ b/games/colorbars/colorbars.c @@ -31,6 +31,8 @@ #include #include +#include + int main(void) { @@ -47,9 +49,9 @@ main(void) { "Cyan", COLOR_CYAN }, { "White", COLOR_WHITE }, }; - size_t lengths[__arysize(colorInfo)]; + size_t lengths[NELEM(colorInfo)]; - static const size_t numcolors = __arysize(colorInfo); + static const size_t numcolors = NELEM(colorInfo); size_t labelwidth; int colorOK; diff --git a/sbin/init/init.c b/sbin/init/init.c index bc99cef2c7..9f18863e81 100644 --- a/sbin/init/init.c +++ b/sbin/init/init.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -526,12 +527,12 @@ get_chroot(void) char *res; int i; - oidlen = __arysize(real_oid); + oidlen = NELEM(real_oid); if (sysctlnametomib("kern.environment", real_oid, &oidlen)) { warning("cannot find kern.environment base sysctl OID"); return NULL; } - if (oidlen + 1 >= __arysize(real_oid)) { + if (oidlen + 1 >= NELEM(real_oid)) { warning("kern.environment OID is too large!"); return NULL; } diff --git a/sys/cpu/x86_64/include/stdint.h b/sys/cpu/x86_64/include/stdint.h index 4714ea52ba..43c0e43045 100644 --- a/sys/cpu/x86_64/include/stdint.h +++ b/sys/cpu/x86_64/include/stdint.h @@ -145,6 +145,4 @@ typedef __int64_t __rlim_t; #endif #endif -#define __arysize(ary) (sizeof(ary)/sizeof((ary)[0])) - #endif /* _CPU_STDINT_H_ */ diff --git a/sys/sys/param.h b/sys/sys/param.h index 869c394813..e8f1f855a5 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -294,7 +294,7 @@ #ifndef howmany #define howmany(x, y) (((x)+((y)-1))/(y)) #endif -#define nitems(x) (sizeof((x)) / sizeof((x)[0])) +#define nitems(x) NELEM(x) #define rounddown(x, y) (((x)/(y))*(y)) #define rounddown2(x, y) ((x) & ~((y) - 1)) /* y power of two */ #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ diff --git a/usr.bin/c89/c89.c b/usr.bin/c89/c89.c index 0ae2501319..486461b362 100644 --- a/usr.bin/c89/c89.c +++ b/usr.bin/c89/c89.c @@ -36,8 +36,10 @@ #include +#include + #define CC "/usr/bin/cc" /* The big kahuna doing the actual work. */ -#define N_ARGS_PREPENDED __arysize(args_prepended) +#define N_ARGS_PREPENDED NELEM(args_prepended) /* * We do not add -D_POSIX_SOURCE here because any POSIX source is supposed to diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index 7ee06f0dcd..2aa65221a2 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -245,7 +246,7 @@ main(int argc, char **argv) if ((c = kvm_nlist(kd, namelist)) != 0) { if (c > 0) { warnx("undefined symbols:"); - for (c = 0; c < (int)__arysize(namelist); c++) + for (c = 0; c < (int)NELEM(namelist); c++) if (namelist[c].n_type == 0) fprintf(stderr, " %s", namelist[c].n_name); -- 2.11.4.GIT