summaryrefslogtreecommitdiffstats
path: root/src/alloc.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-11-22 16:52:33 -0500
committerTavian Barnes <tavianator@tavianator.com>2023-11-23 13:56:03 -0500
commit3fe1e7ca64bcd3724b00cf399ed9ae6f60e0a008 (patch)
tree75bb5d7ecbbc72edcd88e3d6c19c3e05be848957 /src/alloc.h
parentb9ed3f51d636bb0f182b0cc8a86ebf928b37f8c5 (diff)
downloadbfs-3fe1e7ca64bcd3724b00cf399ed9ae6f60e0a008.tar.xz
alloc: New is_aligned() helper
Diffstat (limited to 'src/alloc.h')
-rw-r--r--src/alloc.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/alloc.h b/src/alloc.h
index 34f6949..15e4983 100644
--- a/src/alloc.h
+++ b/src/alloc.h
@@ -11,6 +11,11 @@
#include "config.h"
#include <stdlib.h>
+/** Check if a size is properly aligned. */
+static inline bool is_aligned(size_t align, size_t size) {
+ return (size & (align - 1)) == 0;
+}
+
/** Round down to a multiple of an alignment. */
static inline size_t align_floor(size_t align, size_t size) {
return size & ~(align - 1);