mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-20 14:03:39 +03:00
util: add log2u(), log2u_round_up()
Two's logarithms for unsigned.
This commit is contained in:
parent
a09abc4ae0
commit
b5de6d9842
@ -830,6 +830,21 @@ static inline int log2i(int x) {
|
||||
return __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1;
|
||||
}
|
||||
|
||||
static inline unsigned log2u(unsigned x) {
|
||||
assert(x > 0);
|
||||
|
||||
return sizeof(unsigned) * 8 - __builtin_clz(x) - 1;
|
||||
}
|
||||
|
||||
static inline unsigned log2u_round_up(unsigned x) {
|
||||
assert(x > 0);
|
||||
|
||||
if (x == 1)
|
||||
return 0;
|
||||
|
||||
return log2u(x - 1) + 1;
|
||||
}
|
||||
|
||||
static inline bool logind_running(void) {
|
||||
return access("/run/systemd/seats/", F_OK) >= 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user