aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-06-29 17:11:06 +0200
committerMattias Andrée <maandree@kth.se>2024-06-29 17:11:06 +0200
commit2d325db65a6ea4603d048593df39537d204e932a (patch)
treef187e04c90e8a931e6696796c3cb3ab01249a017
parentAdd (libsimple_)_[v]e[n]printf (diff)
downloadlibsimple-2d325db65a6ea4603d048593df39537d204e932a.tar.gz
libsimple-2d325db65a6ea4603d048593df39537d204e932a.tar.bz2
libsimple-2d325db65a6ea4603d048593df39537d204e932a.tar.xz
Properly fix support for version of C before C11
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--libsimple.h2
-rw-r--r--libsimple/aligned_allocz.h11
2 files changed, 12 insertions, 1 deletions
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