- int i;
-
- if (dir->state == FcGCDirDisabled)
- continue;
- truncate_to += strlen(dir->name) + 1;
- truncate_to += sizeof (FcCache);
- truncate_to = FcCacheNextOffset (truncate_to);
- truncate_to += dir->metadata.count;
-
- for (i = 0; i < dir->subdirs->size; i++)
- truncate_to += strlen((char *)dir->subdirs->strs[i]) + 1;
- truncate_to ++;
- }
- truncate_to -= current_arch_start;
-
- sprintf (header, "%8x ", (int)truncate_to);
- strcat (header, current_arch_machine_name);
- if (!FcCacheWriteString (fd, header))
- goto bail4;
-
- free (header);
-
- for (dir = cache->dirs; dir; dir = dir->next)
- {
- int i;
- const char * d;
- off_t off;
-
- if (!dir->name || dir->state == FcGCDirDisabled)
- continue;
- d = (const char *)FcConfigNormalizeFontDir (config, (const FcChar8 *)dir->name);
- if (!d)
- continue;
-
- if (dir->metadata.count && !dir->ent)
- {
- if (dir->state == FcGCDirUpdated || fd_orig < 0)
- {
- fprintf(stderr, "Invalid metadata entry for %s, skipping...\n", d);
- continue;
- }
- /* copy the old content */
- dir->ent = malloc (dir->metadata.count);
- if (!dir->ent)
- {
- perror("malloc error");
- continue;
- }
- off = FcCacheNextOffset (dir->offset + sizeof(FcCache));
- if (lseek (fd_orig, off, SEEK_SET) != off)
- {
- perror("lseek");
- free(dir->ent);
- continue;
- }
- if (read (fd_orig, dir->ent, dir->metadata.count)
- != dir->metadata.count)
- {
- perror("read");
- free(dir->ent);
- continue;
- }
- }
-
- FcCacheWriteString (fd, d);
-
- for (i = 0; i < dir->subdirs->size; i++)
- FcCacheWriteString (fd, (char *)dir->subdirs->strs[i]);
- FcCacheWriteString (fd, "");
-
- if (write (fd, &dir->metadata, sizeof(FcCache)) != sizeof(FcCache))
- {
- perror ("write metadata");
- free (dir->ent);
- continue;
- }
- off = FcCacheNextOffset (lseek(fd, 0, SEEK_CUR));
- if (lseek (fd, off, SEEK_SET) != off)
- {
- perror ("lseek");
- free (dir->ent);
- continue;
- }
- if (dir->metadata.count)
- {
- if (write (fd, dir->ent, dir->metadata.count) != dir->metadata.count)
- {
- perror ("write dirent");
- free (dir->ent);
- continue;
- }
- }
- free (dir->ent);