summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@neko.keithp.com>2006-09-17 14:20:18 -0700
committerKeith Packard <keithp@neko.keithp.com>2006-09-17 14:20:18 -0700
commitcc104e6a910427db009be36ec34125962889ecb8 (patch)
tree8c398712fdc64a46003c12a98f4067ffec321b95
parent706a1b367abc4589c7eccfd7cea3af1029bc2d8c (diff)
Detect and use available random number generator (bug 8308)
Prefer random over lrand48 over rand
-rw-r--r--configure.in2
-rw-r--r--src/fccache.c13
2 files changed, 13 insertions, 2 deletions
diff --git a/configure.in b/configure.in
index 06bdf52..98604c3 100644
--- a/configure.in
+++ b/configure.in
@@ -166,7 +166,7 @@ AC_TYPE_PID_T
# Checks for library functions.
AC_FUNC_VPRINTF
AC_FUNC_MMAP
-AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr strtol getopt getopt_long sysconf ftruncate chsize rand_r])
+AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr strtol getopt getopt_long sysconf ftruncate chsize rand random lrand48])
#
# Checks for iconv
diff --git a/src/fccache.c b/src/fccache.c
index e289c5d..7e2c1be 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -213,6 +213,17 @@ struct _FcCacheSkip {
static FcCacheSkip *fcCacheChains[FC_CACHE_MAX_LEVEL];
static int fcCacheMaxLevel;
+#if HAVE_RANDOM
+# define FcRandom() random()
+#else
+# if HAVE_LRAND48
+# define FcRandom() lrand48()
+# else
+# if HAVE_RAND
+# define FcRandom() rand()
+# endif
+# endif
+#endif
/*
* Generate a random level number, distributed
* so that each level is 1/4 as likely as the one before
@@ -223,7 +234,7 @@ static int
random_level (void)
{
/* tricky bit -- each bit is '1' 75% of the time */
- long int bits = random () | random ();
+ long int bits = FcRandom () | FcRandom ();
int level = 0;
while (++level < FC_CACHE_MAX_LEVEL)