]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccache.c
Fix warning.
[fontconfig.git] / src / fccache.c
index e8364744de55709e90eb319625c5bafbe269c766..90d08942152df91c06e84054e244aca53b9c415b 100644 (file)
@@ -82,68 +82,43 @@ static void MD5Transform(FcChar32 buf[4], FcChar32 in[16]);
 static char *
 FcCacheReadString (int fd, char *dest, int len)
 {
-    FcChar8    c;
-    FcBool     escape;
-    int                size;
-    int                i;
+    int    size;
+    int    slen;
 
     if (len == 0)
        return 0;
-    
-    size = len;
-    i = 0;
-    escape = FcFalse;
-    while (read (fd, &c, 1) == 1)
+
+    size = read (fd, dest, len-1);
+
+    if (size > 0)
     {
-       if (!escape)
-       {
-           switch (c) {
-           case '"':
-               c = '\0';
-               break;
-           case '\\':
-               escape = FcTrue;
-               continue;
-           }
-       }
-       if (i == size)
-       {
-           dest[i++] = 0;
-           return dest;
-       }
-       dest[i++] = c;
-       if (c == '\0')
-           return dest;
-       escape = FcFalse;
+       dest[size] = '\0';
+       slen = strlen (dest);
+
+       lseek (fd, slen - size + 1, SEEK_CUR);
+       return slen < len ? dest : 0;
     }
+
     return 0;
 }
 
 static void
 FcCacheSkipString (int fd)
 {
-    FcChar8    c;
-    FcBool     escape;
+    char buf[256];
+    int  size;
+    int  slen;
 
-    escape = FcFalse;
-    while (read (fd, &c, 1) == 1)
+    while ( (size = read (fd, buf, sizeof (buf)-1)) > 0) 
     {
-       if (!escape)
-       {
-           switch (c) {
-           case '"':
-               c = '\0';
-               break;
-           case '\\':
-               escape = FcTrue;
-               continue;
-           }
-       }
-       if (c == '\0')
-           return;
-       escape = FcFalse;
+        buf [size] = '\0';
+        slen = strlen (buf);
+        if (slen < size) 
+        {
+            lseek (fd, slen - size + 1, SEEK_CUR);
+            return;
+        }
     }
-    return;
 }
 
 static FcBool
@@ -863,11 +838,10 @@ FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config)
 
 static int
 FcCacheReadDirs (FcConfig * config, FcGlobalCache * cache, 
-                FcStrList *list, FcFontSet * set)
+                FcStrList *list, FcFontSet * set, FcStrSet *processed_dirs)
 {
     int                        ret = 0;
     FcChar8            *dir;
-    const FcChar8      *name;
     FcStrSet           *subdirs;
     FcStrList          *sublist;
     struct stat                statb;
@@ -883,14 +857,16 @@ FcCacheReadDirs (FcConfig * config, FcGlobalCache * cache,
 
        /* Skip this directory if already updated
         * to avoid the looped directories via symlinks
+        * Clearly a dir not in fonts.conf shouldn't be globally cached.
         */
-       name = FcConfigNormalizeFontDir (config, dir);
-       if (name) 
-       {
-           if ((d = FcGlobalCacheDirFind (cache, (const char *)name)) != NULL &&
-               d->state == FcGCDirUpdated)
-               continue;
-       }
+       dir = (FcChar8 *)FcConfigNormalizeFontDir (config, dir);
+       if (!dir)
+           continue;
+
+       if (FcStrSetMember (processed_dirs, dir))
+           continue;
+       if (!FcStrSetAdd (processed_dirs, dir))
+           continue;
 
        subdirs = FcStrSetCreate ();
        if (!subdirs)
@@ -932,7 +908,7 @@ FcCacheReadDirs (FcConfig * config, FcGlobalCache * cache,
        if (FcDirCacheValid (dir) && FcDirCacheRead (set, subdirs, dir, config))
        {
            /* if an old entry is found in the global cache, disable it */
-           if ((d = FcGlobalCacheDirFind (cache, (const char *)name)) != NULL)
+           if ((d = FcGlobalCacheDirFind (cache, (const char *)dir)) != NULL)
            {
                d->state = FcGCDirDisabled;
                /* save the updated config later without this entry */
@@ -955,7 +931,7 @@ FcCacheReadDirs (FcConfig * config, FcGlobalCache * cache,
            ret++;
            continue;
        }
-       ret += FcCacheReadDirs (config, cache, sublist, set);
+       ret += FcCacheReadDirs (config, cache, sublist, set, processed_dirs);
     }
     FcStrListDone (list);
     return ret;
@@ -964,15 +940,24 @@ FcCacheReadDirs (FcConfig * config, FcGlobalCache * cache,
 FcFontSet *
 FcCacheRead (FcConfig *config, FcGlobalCache * cache)
 {
-    FcFontSet * s = FcFontSetCreate();
+    FcFontSet  *s = FcFontSetCreate();
+    FcStrSet   *processed_dirs;
+
     if (!s) 
        return 0;
 
-    if (FcCacheReadDirs (config, cache, FcConfigGetConfigDirs (config), s))
+    processed_dirs = FcStrSetCreate();
+    if (!processed_dirs)
        goto bail;
 
+    if (FcCacheReadDirs (config, cache, FcConfigGetConfigDirs (config), s, processed_dirs))
+       goto bail1;
+
+    FcStrSetDestroy (processed_dirs);
     return s;
 
+ bail1:
+    FcStrSetDestroy (processed_dirs);
  bail:
     FcFontSetDestroy (s);
     return 0;