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.
This commit is contained in:
parent
da72d0ec06
commit
bf51882a09
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=298120
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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);
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user