libc: use our roundup2/rounddown2() macros when param.h is available.

rounddown2 tends to produce longer lines than the original code but
still it makes the code more readable.
This commit is contained in:
Pedro F. Giffuni 2016-04-20 01:21:39 +00:00
parent 523af57ea2
commit 75a5de5a40
3 changed files with 6 additions and 6 deletions

View File

@ -677,7 +677,7 @@ overflow_page(HTAB *hashp)
bit = hashp->LAST_FREED &
((hashp->BSIZE << BYTE_SHIFT) - 1);
j = bit / BITS_PER_MAP;
bit = bit & ~(BITS_PER_MAP - 1);
bit = rounddown2(bit, BITS_PER_MAP);
} else {
bit = 0;
j = 0;

View File

@ -130,8 +130,7 @@ inet6_option_append(struct cmsghdr *cmsg, const u_int8_t *typep, int multx,
/* calculate pad length before the option. */
off = bp - (u_char *)eh;
padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) -
(off % multx);
padlen = roundup2(off % multx, multx) - (off % multx);
padlen += plusy;
padlen %= multx; /* keep the pad as short as possible */
/* insert padding */
@ -200,7 +199,7 @@ inet6_option_alloc(struct cmsghdr *cmsg, int datalen, int multx, int plusy)
/* calculate pad length before the option. */
off = bp - (u_char *)eh;
padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) -
padlen = roundup2(off % multx, multx) -
(off % multx);
padlen += plusy;
padlen %= multx; /* keep the pad as short as possible */

View File

@ -330,7 +330,7 @@ getipnodebyaddr(const void *src, size_t len, int af, int *errp)
*errp = NO_RECOVERY;
return NULL;
}
if ((long)src & ~(sizeof(struct in_addr) - 1)) {
if (rounddown2((long)src, sizeof(struct in_addr))) {
memcpy(&addrbuf, src, len);
src = &addrbuf;
}
@ -343,7 +343,8 @@ getipnodebyaddr(const void *src, size_t len, int af, int *errp)
*errp = NO_RECOVERY;
return NULL;
}
if ((long)src & ~(sizeof(struct in6_addr) / 2 - 1)) { /*XXX*/
if (rounddown2((long)src, sizeof(struct in6_addr) / 2)) {
/* XXX */
memcpy(&addrbuf, src, len);
src = &addrbuf;
}