aboutsummaryrefslogtreecommitdiffstats
path: root/editors/nvi2/files/patch-common_mem.h
blob: 9b18726f869621d99317e61fb75b7aefa991d643 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
--- common/mem.h.orig	2023-09-25 08:47:42 UTC
+++ common/mem.h
@@ -212,6 +212,18 @@ p2roundup(size_t n)
 	return (n);
 }
 
+/*
+ * is_aligned --
+ *      Determine whether the program can safely read an object with an
+ *      alignment requirement from ptr.
+ *
+ * See also: https://clang.llvm.org/docs/LanguageExtensions.html#alignment-builtins
+ */
+static __inline int
+is_aligned(void *ptr, size_t alignment) {
+	return ((uintptr_t)ptr % alignment) == 0;
+}
+
 /* Additional TAILQ helper. */
 #define TAILQ_ENTRY_ISVALID(elm, field)					\
 	((elm)->field.tqe_prev != NULL)