diff options
author | Pedro F. Giffuni <pfg@FreeBSD.org> | 2016-04-16 17:52:00 +0000 |
---|---|---|
committer | Pedro F. Giffuni <pfg@FreeBSD.org> | 2016-04-16 17:52:00 +0000 |
commit | bf51882a09fb19789665c0b385c5fa2f51331079 (patch) | |
tree | 9591d290a7b32152d9fdda623974bad433ef861f /lib/libc | |
parent | da72d0ec065f48c496818cccc459f97c565c99d9 (diff) | |
download | src-bf51882a09fb19789665c0b385c5fa2f51331079.tar.gz src-bf51882a09fb19789665c0b385c5fa2f51331079.zip |
libc: make some more use of the nitems() macro.
We have an nitems() macro in the <sys/param.h> header that is
convenient to re-use as it makes things easier to read.
Given that it is available already without adding additional
headers and other parts of libc already use it, extend a bit
more its use.
Notes
Notes:
svn path=/head/; revision=298120
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/getpwent.c | 2 | ||||
-rw-r--r-- | lib/libc/gen/nlist.c | 2 | ||||
-rw-r--r-- | lib/libc/net/getaddrinfo.c | 6 | ||||
-rw-r--r-- | lib/libc/net/name6.c | 4 | ||||
-rw-r--r-- | lib/libc/powerpc/gen/syncicache.c | 4 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/syncicache.c | 4 | ||||
-rw-r--r-- | lib/libc/resolv/herror.c | 2 | ||||
-rw-r--r-- | lib/libc/resolv/res_mkquery.c | 2 | ||||
-rw-r--r-- | lib/libc/resolv/res_mkupdate.c | 2 | ||||
-rw-r--r-- | lib/libc/xdr/xdr_float.c | 20 |
10 files changed, 22 insertions, 26 deletions
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index 8617ecc0836a..a35a28835004 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -748,7 +748,7 @@ pwdbopen(int *version) else *version = 3; if (*version < 3 || - *version >= sizeof(pwdb_versions)/sizeof(pwdb_versions[0])) { + *version >= nitems(pwdb_versions)) { syslog(LOG_CRIT, "Unsupported password database version %d", *version); res->close(res); diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c index 80784dd8e138..f5631771de6b 100644 --- a/lib/libc/gen/nlist.c +++ b/lib/libc/gen/nlist.c @@ -93,7 +93,7 @@ __fdnlist(int fd, struct nlist *list) int n = -1; unsigned int i; - for (i = 0; i < sizeof(nlist_fn) / sizeof(nlist_fn[0]); i++) { + for (i = 0; i < nitems(nlist_fn); i++) { n = (nlist_fn[i].fn)(fd, list); if (n != -1) break; diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index e2eb1a0f9ae8..88a172c80e3e 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -398,7 +398,7 @@ getaddrinfo(const char *hostname, const char *servname, struct addrinfo *pai; const struct afd *afd; const struct explore *ex; - struct addrinfo *afailist[sizeof(afdl)/sizeof(afdl[0])]; + struct addrinfo *afailist[nitems(afdl)]; struct addrinfo *afai_unspec; int found; int numeric = 0; @@ -736,13 +736,13 @@ get_addrselectpolicy(struct policyhead *head) char *buf; struct in6_addrpolicy *pol, *ep; - if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) + if (sysctl(mib, nitems(mib), NULL, &l, NULL, 0) < 0) return (0); if (l == 0) return (0); if ((buf = malloc(l)) == NULL) return (0); - if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) { + if (sysctl(mib, nitems(mib), buf, &l, NULL, 0) < 0) { free(buf); return (0); } diff --git a/lib/libc/net/name6.c b/lib/libc/net/name6.c index 51e2da15a23f..1d37329a4d34 100644 --- a/lib/libc/net/name6.c +++ b/lib/libc/net/name6.c @@ -735,11 +735,11 @@ get_addrselectpolicy(struct policyhead *head) char *buf; struct in6_addrpolicy *pol, *ep; - if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) + if (sysctl(mib, nitems(mib), NULL, &l, NULL, 0) < 0) return (0); if ((buf = malloc(l)) == NULL) return (0); - if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) { + if (sysctl(mib, nitems(mib), buf, &l, NULL, 0) < 0) { free(buf); return (0); } diff --git a/lib/libc/powerpc/gen/syncicache.c b/lib/libc/powerpc/gen/syncicache.c index 434dcec63416..aa025cca8bc6 100644 --- a/lib/libc/powerpc/gen/syncicache.c +++ b/lib/libc/powerpc/gen/syncicache.c @@ -66,8 +66,8 @@ getcachelinesize() clen = sizeof(cacheline_size); - if (sysctl(cachemib, sizeof(cachemib) / sizeof(cachemib[0]), - &cacheline_size, &clen, NULL, 0) < 0 || !cacheline_size) { + if (sysctl(cachemib, nitems(cachemib), &cacheline_size, &clen, + NULL, 0) < 0 || !cacheline_size) { abort(); } } diff --git a/lib/libc/powerpc64/gen/syncicache.c b/lib/libc/powerpc64/gen/syncicache.c index 1267c9fcc366..f9cc8bcde8a0 100644 --- a/lib/libc/powerpc64/gen/syncicache.c +++ b/lib/libc/powerpc64/gen/syncicache.c @@ -66,8 +66,8 @@ getcachelinesize() clen = sizeof(cacheline_size); - if (sysctl(cachemib, sizeof(cachemib) / sizeof(cachemib[0]), - &cacheline_size, &clen, NULL, 0) < 0 || !cacheline_size) { + if (sysctl(cachemib, nitems(cachemib), &cacheline_size, &clen, + NULL, 0) < 0 || !cacheline_size) { abort(); } } diff --git a/lib/libc/resolv/herror.c b/lib/libc/resolv/herror.c index d9876095c39d..aeb308c2acd1 100644 --- a/lib/libc/resolv/herror.c +++ b/lib/libc/resolv/herror.c @@ -76,7 +76,7 @@ const char *h_errlist[] = { "Unknown server error", /*%< 3 NO_RECOVERY */ "No address associated with name", /*%< 4 NO_ADDRESS */ }; -const int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; +const int h_nerr = { nitems(h_errlist) }; #undef h_errno int h_errno; diff --git a/lib/libc/resolv/res_mkquery.c b/lib/libc/resolv/res_mkquery.c index 0d45e34ddb11..349160fc8189 100644 --- a/lib/libc/resolv/res_mkquery.c +++ b/lib/libc/resolv/res_mkquery.c @@ -133,7 +133,7 @@ res_nmkquery(res_state statp, dpp = dnptrs; *dpp++ = buf; *dpp++ = NULL; - lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0]; + lastdnptr = dnptrs + nitems(dnptrs); /* * perform opcode specific processing */ diff --git a/lib/libc/resolv/res_mkupdate.c b/lib/libc/resolv/res_mkupdate.c index 3ebb24238d22..79402a781682 100644 --- a/lib/libc/resolv/res_mkupdate.c +++ b/lib/libc/resolv/res_mkupdate.c @@ -127,7 +127,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { dpp = dnptrs; *dpp++ = buf; *dpp++ = NULL; - lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0]; + lastdnptr = dnptrs + nitems(dnptrs); if (rrecp_start == NULL) return (-5); diff --git a/lib/libc/xdr/xdr_float.c b/lib/libc/xdr/xdr_float.c index 551f10f394aa..723a81d58bf2 100644 --- a/lib/libc/xdr/xdr_float.c +++ b/lib/libc/xdr/xdr_float.c @@ -111,9 +111,8 @@ xdr_float(XDR *xdrs, float *fp) return (XDR_PUTINT32(xdrs, (int32_t *)fp)); #else vs = *((struct vax_single *)fp); - for (i = 0, lim = sgl_limits; - i < sizeof(sgl_limits)/sizeof(struct sgl_limits); - i++, lim++) { + for (i = 0, lim = sgl_limits; i < nitems(sgl_limits); + i++, lim++) { if ((vs.mantissa2 == lim->s.mantissa2) && (vs.exp == lim->s.exp) && (vs.mantissa1 == lim->s.mantissa1)) { @@ -135,9 +134,8 @@ xdr_float(XDR *xdrs, float *fp) vsp = (struct vax_single *)fp; if (!XDR_GETINT32(xdrs, (int32_t *)&is)) return (FALSE); - for (i = 0, lim = sgl_limits; - i < sizeof(sgl_limits)/sizeof(struct sgl_limits); - i++, lim++) { + for (i = 0, lim = sgl_limits; i < nitems(sgl_limits); + i++, lim++) { if ((is.exp == lim->ieee.exp) && (is.mantissa == lim->ieee.mantissa)) { *vsp = lim->s; @@ -228,9 +226,8 @@ xdr_double(XDR *xdrs, double *dp) return (rv); #else vd = *((struct vax_double *)dp); - for (i = 0, lim = dbl_limits; - i < sizeof(dbl_limits)/sizeof(struct dbl_limits); - i++, lim++) { + for (i = 0, lim = dbl_limits; i < nitems(dbl_limits); + i++, lim++) { if ((vd.mantissa4 == lim->d.mantissa4) && (vd.mantissa3 == lim->d.mantissa3) && (vd.mantissa2 == lim->d.mantissa2) && @@ -270,9 +267,8 @@ xdr_double(XDR *xdrs, double *dp) lp = (int32_t *)&id; if (!XDR_GETINT32(xdrs, lp++) || !XDR_GETINT32(xdrs, lp)) return (FALSE); - for (i = 0, lim = dbl_limits; - i < sizeof(dbl_limits)/sizeof(struct dbl_limits); - i++, lim++) { + for (i = 0, lim = dbl_limits; i < nitems(dbl_limits); + i++, lim++) { if ((id.mantissa2 == lim->ieee.mantissa2) && (id.mantissa1 == lim->ieee.mantissa1) && (id.exp == lim->ieee.exp)) { |