svn commit: r298120 - in head/lib/libc: gen net powerpc/gen powerpc64/gen resolv xdr
Pedro F. Giffuni
pfg at FreeBSD.org
Sat Apr 16 17:52:02 UTC 2016
Author: pfg
Date: Sat Apr 16 17:52:00 2016
New Revision: 298120
URL: https://svnweb.freebsd.org/changeset/base/298120
Log:
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.
Modified:
head/lib/libc/gen/getpwent.c
head/lib/libc/gen/nlist.c
head/lib/libc/net/getaddrinfo.c
head/lib/libc/net/name6.c
head/lib/libc/powerpc/gen/syncicache.c
head/lib/libc/powerpc64/gen/syncicache.c
head/lib/libc/resolv/herror.c
head/lib/libc/resolv/res_mkquery.c
head/lib/libc/resolv/res_mkupdate.c
head/lib/libc/xdr/xdr_float.c
Modified: head/lib/libc/gen/getpwent.c
==============================================================================
--- head/lib/libc/gen/getpwent.c Sat Apr 16 17:46:50 2016 (r298119)
+++ head/lib/libc/gen/getpwent.c Sat Apr 16 17:52:00 2016 (r298120)
@@ -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);
Modified: head/lib/libc/gen/nlist.c
==============================================================================
--- head/lib/libc/gen/nlist.c Sat Apr 16 17:46:50 2016 (r298119)
+++ head/lib/libc/gen/nlist.c Sat Apr 16 17:52:00 2016 (r298120)
@@ -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;
Modified: head/lib/libc/net/getaddrinfo.c
==============================================================================
--- head/lib/libc/net/getaddrinfo.c Sat Apr 16 17:46:50 2016 (r298119)
+++ head/lib/libc/net/getaddrinfo.c Sat Apr 16 17:52:00 2016 (r298120)
@@ -398,7 +398,7 @@ getaddrinfo(const char *hostname, const
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 *
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);
}
Modified: head/lib/libc/net/name6.c
==============================================================================
--- head/lib/libc/net/name6.c Sat Apr 16 17:46:50 2016 (r298119)
+++ head/lib/libc/net/name6.c Sat Apr 16 17:52:00 2016 (r298120)
@@ -735,11 +735,11 @@ get_addrselectpolicy(struct policyhead *
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);
}
Modified: head/lib/libc/powerpc/gen/syncicache.c
==============================================================================
--- head/lib/libc/powerpc/gen/syncicache.c Sat Apr 16 17:46:50 2016 (r298119)
+++ head/lib/libc/powerpc/gen/syncicache.c Sat Apr 16 17:52:00 2016 (r298120)
@@ -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();
}
}
Modified: head/lib/libc/powerpc64/gen/syncicache.c
==============================================================================
--- head/lib/libc/powerpc64/gen/syncicache.c Sat Apr 16 17:46:50 2016 (r298119)
+++ head/lib/libc/powerpc64/gen/syncicache.c Sat Apr 16 17:52:00 2016 (r298120)
@@ -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();
}
}
Modified: head/lib/libc/resolv/herror.c
==============================================================================
--- head/lib/libc/resolv/herror.c Sat Apr 16 17:46:50 2016 (r298119)
+++ head/lib/libc/resolv/herror.c Sat Apr 16 17:52:00 2016 (r298120)
@@ -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;
Modified: head/lib/libc/resolv/res_mkquery.c
==============================================================================
--- head/lib/libc/resolv/res_mkquery.c Sat Apr 16 17:46:50 2016 (r298119)
+++ head/lib/libc/resolv/res_mkquery.c Sat Apr 16 17:52:00 2016 (r298120)
@@ -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
*/
Modified: head/lib/libc/resolv/res_mkupdate.c
==============================================================================
--- head/lib/libc/resolv/res_mkupdate.c Sat Apr 16 17:46:50 2016 (r298119)
+++ head/lib/libc/resolv/res_mkupdate.c Sat Apr 16 17:52:00 2016 (r298120)
@@ -127,7 +127,7 @@ res_nmkupdate(res_state statp, ns_updrec
dpp = dnptrs;
*dpp++ = buf;
*dpp++ = NULL;
- lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
+ lastdnptr = dnptrs + nitems(dnptrs);
if (rrecp_start == NULL)
return (-5);
Modified: head/lib/libc/xdr/xdr_float.c
==============================================================================
--- head/lib/libc/xdr/xdr_float.c Sat Apr 16 17:46:50 2016 (r298119)
+++ head/lib/libc/xdr/xdr_float.c Sat Apr 16 17:52:00 2016 (r298120)
@@ -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)) {
More information about the svn-src-head
mailing list