immutable: Add tests.
[gnulib.git] / m4 / memalign.m4
blob6d72655a500aa5c6c08e01628548a74b88b3e64c
1 # 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_MEMALIGN],
9   AC_REQUIRE([gl_MALLOC_H_DEFAULTS])
10   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12   AC_CHECK_FUNCS_ONCE([memalign])
13   if test $ac_cv_func_memalign = yes; then
14     dnl On Solaris 11, memalign (2, n) always returns NULL.
15     AC_CACHE_CHECK([whether memalign works for small alignments],
16       [gl_cv_func_memalign_works],
17       [AC_RUN_IFELSE(
18          [AC_LANG_PROGRAM(
19             [[#include <malloc.h>
20               #include <stdlib.h>
21             ]],
22             [[int result = 0;
23               if (memalign (1, 1) == NULL)
24                 result |= 1;
25               if (memalign (2, 1) == NULL)
26                 result |= 2;
27               return result;
28             ]])
29          ],
30          [gl_cv_func_memalign_works=yes],
31          [gl_cv_func_memalign_works=no],
32          [case "$host_os" in
33                       # Guess no on Solaris.
34             solaris*) gl_cv_func_memalign_works="guessing no" ;;
35                       # If we don't know, obey --enable-cross-guesses.
36             *)        gl_cv_func_memalign_works="$gl_cross_guess_normal" ;;
37           esac
38          ])
39       ])
40     case "$gl_cv_func_memalign_works" in
41       *yes) ;;
42       *) REPLACE_MEMALIGN=1 ;;
43     esac
44   else
45     dnl The system does not have memalign.
46     HAVE_MEMALIGN=0
47   fi