summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt6
-rwxr-xr-xconfigure19
-rw-r--r--zutil.c2
-rw-r--r--zutil_p.h8
4 files changed, 32 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f6a56f0..57bb764 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -370,6 +370,12 @@ check_function_exists(strerror HAVE_STRERROR)
if(NOT HAVE_STRERROR)
add_definitions(-DNO_STRERROR)
endif()
+set(CMAKE_REQUIRED_DEFINITIONS -D _POSIX_C_SOURCE=200112L)
+check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN)
+if(HAVE_POSIX_MEMALIGN)
+ add_definitions(-DHAVE_POSIX_MEMALIGN)
+endif()
+set(CMAKE_REQUIRED_DEFINITIONS)
if(WITH_SANITIZER STREQUAL "Address")
add_address_sanitizer()
diff --git a/configure b/configure
index 353cad4..afc07f9 100755
--- a/configure
+++ b/configure
@@ -740,7 +740,26 @@ EOF
echo "Checking for fseeko... No." | tee -a configure.log
fi
fi
+echo >> configure.log
+cat > $test.c <<EOF
+#define _POSIX_C_SOURCE 200112L
+#include <stdlib.h>
+int main(void) {
+ void *ptr = 0;
+ int ret = posix_memalign(&ptr, 64, 10);
+ if (ptr)
+ free(ptr);
+ return ret;
+}
+EOF
+if try $CC $CFLAGS -o $test $test.c $LDSHAREDLIBC; then
+ echo "Checking for posix_memalign... Yes." | tee -a configure.log
+ CFLAGS="${CFLAGS} -DHAVE_POSIX_MEMALIGN"
+ SFLAGS="${SFLAGS} -DHAVE_POSIX_MEMALIGN"
+else
+ echo "Checking for posix_memalign... No." | tee -a configure.log
+fi
echo >> configure.log
# check for strerror() for use by gz* functions
diff --git a/zutil.c b/zutil.c
index b1dfc11..62edc99 100644
--- a/zutil.c
+++ b/zutil.c
@@ -4,8 +4,8 @@
*/
#include "zbuild.h"
-#include "zutil.h"
#include "zutil_p.h"
+#include "zutil.h"
z_const char * const PREFIX(z_errmsg)[10] = {
(z_const char *)"need dictionary", /* Z_NEED_DICT 2 */
diff --git a/zutil_p.h b/zutil_p.h
index c812260..55f0061 100644
--- a/zutil_p.h
+++ b/zutil_p.h
@@ -5,7 +5,11 @@
#ifndef ZUTIL_P_H
#define ZUTIL_P_H
-#if defined(__APPLE__) || defined(__OpenBSD__)
+#if defined(HAVE_POSIX_MEMALIGN) && !defined(_POSIX_C_SOURCE)
+# define _POSIX_C_SOURCE 200112L /* For posix_memalign(). */
+#endif
+
+#if defined(__APPLE__) || defined(HAVE_POSIX_MEMALIGN)
# include <stdlib.h>
#elif defined(__FreeBSD__)
# include <stdlib.h>
@@ -16,7 +20,7 @@
/* Function to allocate 16 or 64-byte aligned memory */
static inline void *zng_alloc(size_t size) {
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+#ifdef HAVE_POSIX_MEMALIGN
void *ptr;
return posix_memalign(&ptr, 64, size) ? NULL : ptr;
#elif defined(_WIN32)