diff options
author | pfg <pfg@FreeBSD.org> | 2016-04-20 01:21:39 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2016-04-20 01:21:39 +0000 |
commit | 7ce919789adf84fa6f5faf5c751276f3544d0992 (patch) | |
tree | 1485c6e0f8a0235187c9f88de7fe4501ff9c88f1 /lib | |
parent | a83d88847ec6776630c3b69efb8c6dcc2960f1bc (diff) | |
download | FreeBSD-src-7ce919789adf84fa6f5faf5c751276f3544d0992.zip FreeBSD-src-7ce919789adf84fa6f5faf5c751276f3544d0992.tar.gz |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/db/hash/hash_page.c | 2 | ||||
-rw-r--r-- | lib/libc/net/ip6opt.c | 5 | ||||
-rw-r--r-- | lib/libc/net/name6.c | 5 |
3 files changed, 6 insertions, 6 deletions
diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index 8040419..a2bb7cf 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -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; diff --git a/lib/libc/net/ip6opt.c b/lib/libc/net/ip6opt.c index fda2cd4..c2d292f 100644 --- a/lib/libc/net/ip6opt.c +++ b/lib/libc/net/ip6opt.c @@ -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 */ diff --git a/lib/libc/net/name6.c b/lib/libc/net/name6.c index 1d37329..0023eca 100644 --- a/lib/libc/net/name6.c +++ b/lib/libc/net/name6.c @@ -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; } |