immutable: Add tests.
[gnulib.git] / m4 / posix_memalign.m4
blob1c925e0f99cf4d5f8a47c61604b7aeb691a07af9
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],
21       [AC_RUN_IFELSE(
22          [AC_LANG_PROGRAM(
23             [[#include <stdlib.h>
24             ]],
25             [[void *p;
26               if (posix_memalign (&p, 32, 2406) == 0)
27                 if (((unsigned long)p % 32) != 0)
28                   return 1;
29               return 0;
30             ]])
31          ],
32          [gl_cv_func_posix_memalign_works=yes],
33          [gl_cv_func_posix_memalign_works=no],
34          [case "$host_os" in
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" ;;
39           esac
40          ])
41       ])
42     case "$gl_cv_func_posix_memalign_works" in
43       *yes) ;;
44       *) REPLACE_POSIX_MEMALIGN=1 ;;
45     esac
46   else
47     dnl The system does not have posix_memalign.
48     HAVE_POSIX_MEMALIGN=0
49   fi