aboutsummaryrefslogtreecommitdiff
path: root/fontconfig
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-02-29 13:47:34 +0100
committermarha <marha@users.sourceforge.net>2012-02-29 13:47:34 +0100
commitc14f2432d6bfb3de6c6289efd0471f038a289327 (patch)
tree8864ad1e5d0ae65dd665aa45245f2dab86c3f178 /fontconfig
parent8475e285d0146b123f0ac1a87294c42088af12b0 (diff)
parent15a500d3edb03668b43cc6898fafcda024d0f006 (diff)
downloadvcxsrv-c14f2432d6bfb3de6c6289efd0471f038a289327.tar.gz
vcxsrv-c14f2432d6bfb3de6c6289efd0471f038a289327.tar.bz2
vcxsrv-c14f2432d6bfb3de6c6289efd0471f038a289327.zip
Merge remote-tracking branch 'origin/released'
Diffstat (limited to 'fontconfig')
-rw-r--r--fontconfig/configure.in2
-rw-r--r--fontconfig/src/fccache.c69
2 files changed, 60 insertions, 11 deletions
diff --git a/fontconfig/configure.in b/fontconfig/configure.in
index 9f671abe7..06851a5e4 100644
--- a/fontconfig/configure.in
+++ b/fontconfig/configure.in
@@ -119,7 +119,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 random lrand48])
+AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr strtol getopt getopt_long sysconf ftruncate chsize rand random lrand48 random_r rand_r])
#
# Checks for iconv
diff --git a/fontconfig/src/fccache.c b/fontconfig/src/fccache.c
index 054371445..bbf950f17 100644
--- a/fontconfig/src/fccache.c
+++ b/fontconfig/src/fccache.c
@@ -20,14 +20,18 @@
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
-
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
#include "fcint.h"
#include "fcarch.h"
#include <stdio.h>
+#include <stdlib.h>
#include <fcntl.h>
#include <dirent.h>
#include <string.h>
#include <sys/types.h>
+#include <time.h>
#include <assert.h>
#if defined(HAVE_MMAP) || defined(__CYGWIN__)
# include <unistd.h>
@@ -304,17 +308,62 @@ struct _FcCacheSkip {
static FcCacheSkip *fcCacheChains[FC_CACHE_MAX_LEVEL];
static int fcCacheMaxLevel;
-#if HAVE_RANDOM
-# define FcRandom() random()
+
+static int32_t
+FcRandom(void)
+{
+ int32_t result;
+
+#if HAVE_RANDOM_R
+ static struct random_data fcrandbuf;
+ static char statebuf[256];
+ static FcBool initialized = FcFalse;
+
+ if (initialized != FcTrue)
+ {
+ initstate_r(time(NULL), statebuf, 256, &fcrandbuf);
+ initialized = FcTrue;
+ }
+
+ random_r(&fcrandbuf, &result);
+#elif HAVE_RANDOM
+ static char statebuf[256];
+ char *state;
+ static FcBool initialized = FcFalse;
+
+ if (initialized != FcTrue)
+ {
+ state = initstate(time(NULL), statebuf, 256);
+ initialized = FcTrue;
+ }
+ else
+ state = setstate(statebuf);
+
+ result = random();
+
+ setstate(state);
+#elif HAVE_LRAND48
+ result = lrand48();
+#elif HAVE_RAND_R
+ static unsigned int seed = time(NULL);
+
+ result = rand_r(&seed);
+#elif HAVE_RAND
+ static FcBool initialized = FcFalse;
+
+ if (initialized != FcTrue)
+ {
+ srand(time(NULL));
+ initialized = FcTrue;
+ }
+ result = rand();
#else
-# if HAVE_LRAND48
-# define FcRandom() lrand48()
-# else
-# if HAVE_RAND
-# define FcRandom() rand()
-# endif
-# endif
+# error no random number generator function available.
#endif
+
+ return result;
+}
+
/*
* Generate a random level number, distributed
* so that each level is 1/4 as likely as the one before