Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions vrt/vrtd/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,15 @@ void vrtd_log(int priority, const char *fmt, ...)
*/
const char *uid_to_username(uid_t uid, char *buf, size_t bufsz);

#define HAVE_STDBIT 0

#if defined(__has_include)
# if __has_include(<stdbit.h>)
# include <stdbit.h>
# define HAVE_STDBIT 1
# if defined(__STDC_VERSION_STDBIT_H__) && __STDC_VERSION_STDBIT_H__ >= 202311L
# undef HAVE_STDBIT
# define HAVE_STDBIT 1
# endif
# endif
#endif

Expand Down Expand Up @@ -136,7 +141,7 @@ static inline uint64_t bit_ceil_u64(uint64_t n) {
* @return Smallest power of two >= n, or 0 if not representable.
*/
static inline uint32_t bit_ceil_u32(uint32_t n) {
if (n == 0) return 1u;
if (n <= 1) return 1u;
if (n > 0x80000000u) return 0u; // not representable
return 1u << (32 - __builtin_clz(n - 1)); // GCC/Clang
}
Expand All @@ -146,7 +151,7 @@ static inline uint32_t bit_ceil_u32(uint32_t n) {
* @return Smallest power of two >= n, or 0 if not representable.
*/
static inline uint64_t bit_ceil_u64(uint64_t n) {
if (n == 0) return 1ull;
if (n <= 1) return 1ull;
if (n > 0x8000000000000000ull) return 0ull; // not representable
return 1ull << (64 - __builtin_clzll(n - 1));
}
Expand Down
Loading