1 # posix_memalign.m4 serial 1
2 dnl Copyright (C) 2020-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_POSIX_MEMALIGN],
9 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12 dnl Persuade glibc <stdlib.h> to declare posix_memalign().
13 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
15 AC_CHECK_FUNCS_ONCE([posix_memalign])
16 if test $ac_cv_func_posix_memalign = yes; then
17 dnl On OpenBSD 6.1, posix_memalign (&p, 32, 2406) returns a pointer
18 dnl that is not a multiple of 32.
19 AC_CACHE_CHECK([whether posix_memalign works for large alignments],
20 [gl_cv_func_posix_memalign_works],
26 if (posix_memalign (&p, 32, 2406) == 0)
27 if (((unsigned long)p % 32) != 0)
32 [gl_cv_func_posix_memalign_works=yes],
33 [gl_cv_func_posix_memalign_works=no],
35 # Guess no on OpenBSD.
36 openbsd*) gl_cv_func_posix_memalign_works="guessing no" ;;
37 # If we don't know, obey --enable-cross-guesses.
38 *) gl_cv_func_posix_memalign_works="$gl_cross_guess_normal" ;;
42 case "$gl_cv_func_posix_memalign_works" in
44 *) REPLACE_POSIX_MEMALIGN=1 ;;
47 dnl The system does not have posix_memalign.