diff options
-rw-r--r-- | src/pulsecore/core-util.c | 18 | ||||
-rw-r--r-- | src/pulsecore/core-util.h | 3 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 2c5a32e9..0005e220 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -1208,3 +1208,21 @@ char *pa_truncate_utf8(char *c, size_t l) { return c; } + +int pa_is_power_of_two(unsigned n) { + return !(n & (n - 1)); +} + +unsigned pa_make_power_of_two(unsigned n) { + unsigned j = n; + + if (pa_is_power_of_two(n)) + return n; + + while (j) { + j = j >> 1; + n = n | j; + } + + return n + 1; +} diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index cb78d32d..29dc2fb1 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -97,4 +97,7 @@ int pa_snprintf(char *str, size_t size, const char *format, ...); char *pa_truncate_utf8(char *c, size_t l); +int pa_is_power_of_two(unsigned n); +unsigned pa_make_power_of_two(unsigned n); + #endif |