summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index f57a73cec6..a25b2f5aec 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -369,12 +369,32 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
break; \
} else
+static inline void *mempset(void *s, int c, size_t n) {
+ memset(s, c, n);
+ return (uint8_t*)s + n;
+}
+
static inline void _reset_errno_(int *saved_errno) {
errno = *saved_errno;
}
#define PROTECT_ERRNO _cleanup_(_reset_errno_) __attribute__((unused)) int _saved_errno_ = errno
+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;
+}
+
int unlink_noerrno(const char *path);
#define strappenda(a, ...) \