git-merge-changelog: Improve last commit.
[gnulib.git] / m4 / posix_memalign.m4
blobcaae8bae3fcf080c5380952cbbe87f2d35a38ecf
1 # posix_memalign.m4
2 # serial 3
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],
22       [AC_RUN_IFELSE(
23          [AC_LANG_PROGRAM(
24             [[#include <stdlib.h>
25             ]],
26             [[void *p;
27               if (posix_memalign (&p, 32, 2406) == 0)
28                 if (((unsigned long)p % 32) != 0)
29                   return 1;
30               return 0;
31             ]])
32          ],
33          [gl_cv_func_posix_memalign_works=yes],
34          [gl_cv_func_posix_memalign_works=no],
35          [case "$host_os" in
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" ;;
40           esac
41          ])
42       ])
43     case "$gl_cv_func_posix_memalign_works" in
44       *yes) ;;
45       *) REPLACE_POSIX_MEMALIGN=1 ;;
46     esac
47   else
48     dnl The system does not have posix_memalign.
49     HAVE_POSIX_MEMALIGN=0
50     case "$gl_cv_onwards_func_posix_memalign" in
51       future*) REPLACE_POSIX_MEMALIGN=1 ;;
52     esac
53   fi