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