/
niceSOFT
/
dovecot
Обзор
Документация
Войти
/
niceSOFT
/
dovecot
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/lib/bits.c
37 строк
897 B
Michael M Slusarz
COPYING: Simplify and standardize copyright handling
03 июл 2026, 02:25
03 июл 2026, 02:25
2a5809c
Код
Авторство
О чём код?
/* Copyright (c) Dovecot authors, see top-level COPYING file */ #include "lib.h" /* * We could use bits_required64() unconditionally, but that's unnecessary * and way more heavy weight on 32-bit systems. */ #if SIZEOF_SIZE_T > 4 #define BITS_REQUIRED(x) bits_required64(x) #else #define BITS_REQUIRED(x) bits_required32(x) #endif size_t nearest_power(size_t num) { if (unlikely(num > ((size_t)1 << (CHAR_BIT*sizeof(size_t) - 1)))) i_panic("nearest_power(%zu): calculation would overflow", num); if (num == 0) return 1; return 1UL << BITS_REQUIRED(num - 1); } #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) /* Lucky you, it's all inline intrinsics */ #else 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; } #endif