- char name_buf[FC_MAX_FILE_LEN];
- FcGlobalCacheDir *d, *next;
- FcFileTime config_time = FcConfigModifiedTime (config);
- char * current_arch_machine_name;
- char candidate_arch_machine_name[MACHINE_SIGNATURE_SIZE + 9];
- off_t current_arch_start;
-
- struct stat cache_stat, dir_stat;
- char subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
-
- if (stat ((char *) cache_file, &cache_stat) < 0)
- return;
-
- cache->fd = open ((char *) cache_file, O_RDONLY);
- if (cache->fd == -1)
- return;
-
- cache->updated = FcFalse;
-
- if (!FcCacheReadString (cache->fd, name_buf, sizeof (name_buf)))
- return;
- if (strcmp (name_buf, FC_GLOBAL_MAGIC_COOKIE) != 0)
- return;
-
- current_arch_machine_name = FcCacheMachineSignature ();
- current_arch_start = FcCacheSkipToArch(cache->fd,
- current_arch_machine_name);
- if (current_arch_start < 0)
- goto bail_and_destroy;
-
- lseek (cache->fd, current_arch_start, SEEK_SET);
- if (!FcCacheReadString (cache->fd, candidate_arch_machine_name,
- sizeof (candidate_arch_machine_name)))
- goto bail_and_destroy;
- if (strlen(candidate_arch_machine_name) == 0)
- goto bail_and_destroy;
-
- while (1)
- {
- off_t targ;
-
- if (!FcCacheReadString (cache->fd, name_buf, sizeof (name_buf)) || !strlen(name_buf))
- break;
-
- /* Directory must be older than the global cache file; also
- cache must be newer than the config file. */
- if (stat ((char *) name_buf, &dir_stat) < 0 ||
- dir_stat.st_mtime > cache_stat.st_mtime ||
- (config_time.set && cache_stat.st_mtime < config_time.time))
- {
- FcCache md;
-
- FcStrSetAdd (staleDirs, FcStrCopy ((FcChar8 *)name_buf));
- read (cache->fd, &md, sizeof (FcCache));
- lseek (cache->fd, FcCacheNextOffset (lseek(cache->fd, 0, SEEK_CUR)) + md.count, SEEK_SET);
- continue;
- }
-
- d = malloc (sizeof (FcGlobalCacheDir));
- if (!d)
- goto bail1;
-
- d->next = cache->dirs;
- cache->dirs = d;
-
- d->name = (char *)FcStrCopy ((FcChar8 *)name_buf);
- d->ent = 0;
- d->offset = lseek (cache->fd, 0, SEEK_CUR);