]> git.wh0rd.org - fontconfig.git/commitdiff
Detect and use available random number generator (bug 8308)
authorKeith Packard <keithp@neko.keithp.com>
Sun, 17 Sep 2006 21:20:18 +0000 (14:20 -0700)
committerKeith Packard <keithp@neko.keithp.com>
Sun, 17 Sep 2006 21:20:18 +0000 (14:20 -0700)
Prefer random over lrand48 over rand

configure.in
src/fccache.c

index 06bdf5213259f4fbb2a2d16207144115ab83d046..98604c3ad1bb8540ad6dc1e184bed233bc47b108 100644 (file)
@@ -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
index e289c5dd89bd3f8a400a21fb8edacfa0645d42d2..7e2c1bec9363068b2b2ec31fb743a4c00fdec348 100644 (file)
@@ -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)