string-buffer tests: Avoid test failure on native Windows.
[gnulib.git] / m4 / random.m4
blob92cfcd5730edd161cb0e335af49370414d53a54b
1 # random.m4
2 # serial 8
3 dnl Copyright (C) 2012-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_RANDOM],
10   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
11   AC_REQUIRE([AC_CANONICAL_HOST])
13   dnl We can't use AC_CHECK_FUNC here, because random() is defined as a
14   dnl static inline function when compiling for Android 4.4 or older.
15   AC_CACHE_CHECK([for random], [gl_cv_func_random],
16     [AC_LINK_IFELSE(
17        [AC_LANG_PROGRAM(
18           [[#include <stdlib.h>]],
19           [[return random() == 0;]])
20        ],
21        [gl_cv_func_random=yes],
22        [gl_cv_func_random=no])
23     ])
24   gl_CHECK_FUNCS_ANDROID([initstate], [[#include <stdlib.h>]])
25   gl_CHECK_FUNCS_ANDROID([setstate], [[#include <stdlib.h>]])
26   if test $gl_cv_func_random = no; then
27     HAVE_RANDOM=0
28     HAVE_INITSTATE=0
29     HAVE_SETSTATE=0
30   else
31     if test $ac_cv_func_initstate = no; then
32       HAVE_INITSTATE=0
33     fi
34     if test $ac_cv_func_setstate = no; then
35       HAVE_SETSTATE=0
36     fi
37   fi
38   if test $HAVE_INITSTATE = 0; then
39     case "$gl_cv_onwards_func_initstate" in
40       future*) REPLACE_INITSTATE=1 ;;
41     esac
42   fi
43   if test $HAVE_SETSTATE = 0; then
44     case "$gl_cv_onwards_func_setstate" in
45       future*) REPLACE_SETSTATE=1 ;;
46     esac
47   fi
48   dnl On several platforms, random() is not multithread-safe.
49   if test $ac_cv_func_initstate = no || test $ac_cv_func_setstate = no \
50      || case "$host_os" in \
51           darwin* | freebsd* | solaris* | cygwin* | haiku*) true ;; \
52           *) false ;; \
53         esac
54   then
55     dnl In order to define initstate or setstate, we need to define all the
56     dnl functions at once.
57     REPLACE_RANDOM=1
58     if test $ac_cv_func_initstate = yes; then
59       REPLACE_INITSTATE=1
60     fi
61     if test $ac_cv_func_setstate = yes; then
62       REPLACE_SETSTATE=1
63     fi
64   fi
66   AC_CHECK_DECLS_ONCE([initstate])
67   if test $ac_cv_have_decl_initstate = no; then
68     HAVE_DECL_INITSTATE=0
69   fi
71   AC_CHECK_DECLS_ONCE([setstate])
72   if test $ac_cv_have_decl_setstate = no; then
73     HAVE_DECL_SETSTATE=0
74   fi
77 # Prerequisites of lib/random.c.
78 AC_DEFUN([gl_PREREQ_RANDOM], [
79   :