ports/editors/nvi2/files/patch-common_mem.h
Craig Leres ab0fed1b91 editors/nvi2: Update to 26-Apr-2024 (52c07e8)
- In ruler show the current line number as a percentage of the
   total lines

 - Link macro for hyperlink

 - Add showfilename set option

 - Fix undefined string comparison

 - Replace Clang-only __builtin_is_aligned with C code

 - Use memmove to realign buffers
2025-01-14 13:01:28 -08:00

21 lines
579 B
C

--- 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)