]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccache.c
[doc] Fix typo
[fontconfig.git] / src / fccache.c
index f35304a40cde1636a5b6d785c13593e13df227a6..69e1a6b82166532df55dff1957fb58901d5b9a1c 100644 (file)
@@ -12,9 +12,9 @@
  * representations about the suitability of this software for any purpose.  It
  * is provided "as is" without express or implied warranty.
  *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
@@ -553,6 +553,8 @@ FcDirCacheMapFd (int fd, struct stat *fd_stat, struct stat *dir_stat)
     {
 #if defined(HAVE_MMAP) || defined(__CYGWIN__)
        cache = mmap (0, fd_stat->st_size, PROT_READ, MAP_SHARED, fd, 0);
+       if (cache == MAP_FAILED)
+           cache = NULL;
 #elif defined(_WIN32)
        {
            HANDLE hFileMap;
@@ -844,6 +846,8 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
     FcStrList      *list;
     FcChar8        *cache_dir = NULL;
     FcChar8        *test_dir;
+    FcCacheSkip     *skip;
+    struct stat     cache_stat;
     int                    magic;
     int                    written;
 
@@ -929,6 +933,20 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
     close(fd);
     if (!FcAtomicReplaceOrig(atomic))
         goto bail4;
+
+    /* If the file is small, update the cache chain entry such that the
+     * new cache file is not read again.  If it's large, we don't do that
+     * such that we reload it, using mmap, which is shared across processes.
+     */
+    if (cache->size < FC_CACHE_MIN_MMAP &&
+       (skip = FcCacheFindByAddr (cache)) &&
+       FcStat (cache_hashed, &cache_stat))
+    {
+       skip->cache_dev = cache_stat.st_dev;
+       skip->cache_ino = cache_stat.st_ino;
+       skip->cache_mtime = cache_stat.st_mtime;
+    }
+
     FcStrFree (cache_hashed);
     FcAtomicUnlock (atomic);
     FcAtomicDestroy (atomic);