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
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;
/* 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)
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 */
ret++;
continue;
}
- ret += FcCacheReadDirs (config, cache, sublist, set);
+ ret += FcCacheReadDirs (config, cache, sublist, set, processed_dirs);
}
FcStrListDone (list);
return ret;
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;