diff options
author | Nathan Moinvaziri <nathan@nathanm.com> | 2021-06-25 17:23:34 -0700 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2021-12-24 12:52:14 +0100 |
commit | 7bf46bb53b9625fa2b1ed07890687cb50d907c96 (patch) | |
tree | 0a1ade613579ae6a46e1bd028d1b6578619c9b7b | |
parent | 3d7381f4e3cefb27193e5cede9af20ab6d50cfd4 (diff) |
Added build system check for posix_memalign support.
Co-authored-by: concatime <concatime@users.noreply@github.com>
Co-authored-by: Mika Lindqvist <postmaster@raasu.org>
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rwxr-xr-x | configure | 19 | ||||
-rw-r--r-- | zutil.c | 2 | ||||
-rw-r--r-- | zutil_p.h | 8 |
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() @@ -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 @@ -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 */ @@ -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) |