From 2d325db65a6ea4603d048593df39537d204e932a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 29 Jun 2024 17:11:06 +0200 Subject: Properly fix support for version of C before C11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libsimple.h | 2 +- libsimple/aligned_allocz.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libsimple.h b/libsimple.h index 25e9a1a..1b22653 100644 --- a/libsimple.h +++ b/libsimple.h @@ -152,8 +152,8 @@ #include "libsimple/valloc.h" #include "libsimple/pvallocz.h" #include "libsimple/pvalloc.h" -#include "libsimple/aligned_alloc.h" #include "libsimple/aligned_allocz.h" +#include "libsimple/aligned_alloc.h" #include "libsimple/posix_memalignz.h" #include "libsimple/posix_memalign.h" #include "libsimple/env.h" diff --git a/libsimple/aligned_allocz.h b/libsimple/aligned_allocz.h index b27a17b..eb8b34f 100644 --- a/libsimple/aligned_allocz.h +++ b/libsimple/aligned_allocz.h @@ -44,10 +44,21 @@ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size inline void * libsimple_aligned_allocz(int clear__, size_t alignment__, size_t n__) { +#if defined(aligned_alloc) || defined(_ISOC11_SOURCE) void *ret__ = aligned_alloc(alignment__, n__); if (ret__ && clear__) memset(ret__, 0, n__); return ret__; +#else + if (!alignment__ || alignment__ % sizeof(void *))) { + errno = EINVAL; + return NULL; + } + return libsimple_memalloc(n__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, + LIBSIMPLE_MEMALLOC_ALIGNMENT, alignment__, + LIBSIMPLE_MEMALLOC_END); +#endif } #ifndef aligned_allocz # define aligned_allocz libsimple_aligned_allocz -- cgit v1.2.3-70-g09d2