Mercurial > dovecot > core-2.2
view src/lib/bits.c @ 19552:0f22db71df7a
global: freshen copyright
git ls-files | xargs perl -p -i -e 's/(\d+)-201[0-5]/$1-2016/g;s/ (201[0-5]) Dovecot/ $1-2016 Dovecot/'
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Wed, 13 Jan 2016 12:24:03 +0200 |
parents | 3009a1a6f6d5 |
children | 2e2563132d5f |
line wrap: on
line source
/* Copyright (c) 2001-2016 Dovecot authors, see the included COPYING file */ #include "lib.h" size_t nearest_power(size_t num) { size_t n = 1; i_assert(num <= ((size_t)1 << (CHAR_BIT*sizeof(size_t) - 1))); while (n < num) n <<= 1; return n; } unsigned int bits_required8(uint8_t num) { int ret = 0; if (num > 0xf) { ret += 4; num >>= 4; } if (num > 0x3) { ret += 2; num >>= 2; } num &= ~(num>>1); /* 3->2, else unchanged */ return ret + num; }