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()
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
*/
#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 */
#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>
/* 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)