aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-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