]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccache.c
More fixes for Win32 building (bug 8311)
[fontconfig.git] / src / fccache.c
index 11f88a788b2dc84ab5361055aac44f638924ffd7..ba6af72ea880f751f6968968f2b77f08e95dff65 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)
@@ -275,9 +286,18 @@ FcCacheInsert (FcCache *cache, struct stat *cache_stat)
     s->cache = cache;
     s->size = cache->size;
     s->ref = 1;
-    s->cache_dev = cache_stat->st_dev;
-    s->cache_ino = cache_stat->st_ino;
-    s->cache_mtime = cache_stat->st_mtime;
+    if (cache_stat)
+    {
+       s->cache_dev = cache_stat->st_dev;
+       s->cache_ino = cache_stat->st_ino;
+       s->cache_mtime = cache_stat->st_mtime;
+    }
+    else
+    {
+       s->cache_dev = 0;
+       s->cache_ino = 0;
+       s->cache_mtime = 0;
+    }
     
     /*
      * Insert into all fcCacheChains
@@ -434,7 +454,8 @@ FcDirCacheMapFd (int fd, struct stat *fd_stat)
                                         PAGE_READONLY, 0, 0, NULL);
            if (hFileMap != NULL)
            {
-               cache = MapViewOfFile (hFileMap, FILE_MAP_READ, 0, 0, size);
+               cache = MapViewOfFile (hFileMap, FILE_MAP_READ, 0, 0, 
+                                      fd_stat->st_size);
                CloseHandle (hFileMap);
            }
        }
@@ -658,6 +679,8 @@ FcDirCacheBuild (FcFontSet *set, const FcChar8 *dir, FcStrSet *dirs)
 
     FcSerializeDestroy (serialize);
     
+    FcCacheInsert (cache, NULL);
+
     return cache;
 
 bail2:
@@ -667,6 +690,11 @@ bail1:
     return NULL;
 }
 
+
+#ifdef _WIN32
+#define mkdir(path,mode) _mkdir(path)
+#endif
+
 static FcBool
 FcMakeDirectory (const FcChar8 *dir)
 {