diff options
Diffstat (limited to 'src/pulsecore/core-util.h')
-rw-r--r-- | src/pulsecore/core-util.h | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index 838e4ad3..fd6ee896 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -35,6 +35,10 @@ #include <pulse/gccmacro.h> #include <pulsecore/macro.h> +#ifndef PACKAGE +#error "Please include config.h before including this file!" +#endif + struct timeval; /* These resource limits are pretty new on Linux, let's define them @@ -127,8 +131,8 @@ int pa_atoi(const char *s, int32_t *ret_i); int pa_atou(const char *s, uint32_t *ret_u); int pa_atod(const char *s, double *ret_d); -int pa_snprintf(char *str, size_t size, const char *format, ...); -int pa_vsnprintf(char *str, size_t size, const char *format, va_list ap); +size_t pa_snprintf(char *str, size_t size, const char *format, ...); +size_t pa_vsnprintf(char *str, size_t size, const char *format, va_list ap); char *pa_truncate_utf8(char *c, size_t l); @@ -142,29 +146,35 @@ static inline int pa_is_power_of_two(unsigned n) { return !(n & (n - 1)); } -static inline unsigned pa_make_power_of_two(unsigned n) { - unsigned j = n; +static inline unsigned pa_ulog2(unsigned n) { - if (pa_is_power_of_two(n)) - return n; + if (n <= 1) + return 0; - while (j) { - j = j >> 1; - n = n | j; - } +#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) + return 8U * (unsigned) sizeof(unsigned) - (unsigned) __builtin_clz(n) - 1; +#else +{ + unsigned r = 0; - return n + 1; -} + for (;;) { + n = n >> 1; -static inline unsigned pa_ulog2(unsigned n) { - unsigned r = 0; + if (!n) + return r; - while (n) { r++; - n = n >> 1; } +} +#endif +} + +static inline unsigned pa_make_power_of_two(unsigned n) { + + if (pa_is_power_of_two(n)) + return n; - return r; + return 1U << (pa_ulog2(n) + 1); } void pa_close_pipe(int fds[2]); @@ -185,5 +195,15 @@ pa_bool_t pa_in_system_mode(void); #define pa_streq(a,b) (!strcmp((a),(b))) char *pa_machine_id(void); +char *pa_uname_string(void); + + +#ifdef HAVE_VALGRIND_MEMCHECK_H +pa_bool_t pa_in_valgrind(void); +#else +static inline pa_bool_t pa_in_valgrind(void) { + return FALSE; +} +#endif #endif |