mirror of
https://github.com/opnsense/src.git
synced 2026-02-18 18:20:26 -05:00
nvi: Replace Clang-only __builtin_is_aligned with C code (#124)
We should use alignof in the future.
Obtained from: 25c4d7db4e
(cherry picked from commit 06a98fefd3d3ff42b7e7832af6c0736b98f167ac)
This commit is contained in:
parent
3e9f61464e
commit
c71b427bfa
2 changed files with 13 additions and 1 deletions
|
|
@ -709,7 +709,7 @@ apply_with(int (*db_func)(SCR *, recno_t, CHAR_T *, size_t), SCR *sp,
|
|||
static size_t blen;
|
||||
static u_char *bp;
|
||||
|
||||
if (!__builtin_is_aligned(p, sizeof(unsigned long))) {
|
||||
if (!is_aligned(p, sizeof(unsigned long))) {
|
||||
if (len > blen) {
|
||||
blen = p2roundup(MAX(len, 512));
|
||||
REALLOC(sp, bp, u_char *, blen);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue