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],
18 [[#include <stdlib.h>]],
19 [[return random() == 0;]])
21 [gl_cv_func_random=yes],
22 [gl_cv_func_random=no])
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
31 if test $ac_cv_func_initstate = no; then
34 if test $ac_cv_func_setstate = no; then
38 if test $HAVE_INITSTATE = 0; then
39 case "$gl_cv_onwards_func_initstate" in
40 future*) REPLACE_INITSTATE=1 ;;
43 if test $HAVE_SETSTATE = 0; then
44 case "$gl_cv_onwards_func_setstate" in
45 future*) REPLACE_SETSTATE=1 ;;
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 ;; \
55 dnl In order to define initstate or setstate, we need to define all the
56 dnl functions at once.
58 if test $ac_cv_func_initstate = yes; then
61 if test $ac_cv_func_setstate = yes; then
66 AC_CHECK_DECLS_ONCE([initstate])
67 if test $ac_cv_have_decl_initstate = no; then
71 AC_CHECK_DECLS_ONCE([setstate])
72 if test $ac_cv_have_decl_setstate = no; then
77 # Prerequisites of lib/random.c.
78 AC_DEFUN([gl_PREREQ_RANDOM], [