- if (w == -1)
- return w;
-
- if (pagesize == -1)
-#if defined (HAVE_SYSCONF)
- pagesize = sysconf(_SC_PAGESIZE);
-#else
- pagesize = FC_HARDCODED_PAGESIZE;
-#endif
- if (w % pagesize == 0)
- return w;
- else
- return ((w / pagesize)+1)*pagesize;
-}
-
-/* return the address of the segment for the provided arch,
- * or -1 if arch not found */
-static off_t
-FcCacheSkipToArch (int fd, const char * arch)
-{
- char candidate_arch_machine_name_count[MACHINE_SIGNATURE_SIZE + 9];
- char * candidate_arch;
- off_t current_arch_start = 0;
-
- lseek (fd, 0, SEEK_SET);
- FcCacheSkipString (fd);
- current_arch_start = lseek (fd, 0, SEEK_CUR);
-
- /* skip arches that are not the current arch */
- while (1)
- {
- long bs;
-
- if (lseek (fd, current_arch_start, SEEK_SET) != current_arch_start)
- return -1;
-
- if (FcCacheReadString (fd, candidate_arch_machine_name_count,
- sizeof (candidate_arch_machine_name_count)) == 0)
- return -1;
- if (!strlen(candidate_arch_machine_name_count))
- return -1;
- bs = strtol(candidate_arch_machine_name_count, &candidate_arch, 16);
-
- /* count = 0 should probably be distinguished from the !bs condition */
- if (!bs || bs < strlen (candidate_arch_machine_name_count))
- return -1;
-
- candidate_arch++; /* skip leading space */
-
- if (strcmp (candidate_arch, arch)==0)
- return current_arch_start;
- current_arch_start += bs;
- current_arch_start = FcCacheNextOffset (current_arch_start);
- }
-}
-
-/* Cuts out the segment at the file pointer (moves everything else
- * down to cover it), and leaves the file pointer at the end of the
- * file. */
-static FcBool
-FcCacheCopyOld (int fd, int fd_orig, off_t start)
-{
- char * buf = malloc (8192);
- char candidate_arch_machine_name[MACHINE_SIGNATURE_SIZE + 9];
- long bs;
- int c, bytes_skipped;
- off_t loc;
-
- if (!buf)
- return FcFalse;
-
- loc = 0;
- lseek (fd, 0, SEEK_SET); lseek (fd_orig, 0, SEEK_SET);
- FcCacheSkipString (fd); FcCacheSkipString (fd_orig);
- do
- {
- int b = 8192;
- if (loc + b > start)
- b = start - loc;
-
- if ((c = read (fd_orig, buf, b)) <= 0)
- break;
- if (write (fd, buf, c) < 0)
- goto bail;
-
- loc += c;
- }
- while (c > 0);
-
- lseek (fd, start, SEEK_SET);
- if (FcCacheReadString (fd, candidate_arch_machine_name,
- sizeof (candidate_arch_machine_name)) == 0)
- goto done;
- if (!strlen(candidate_arch_machine_name))
- goto done;
-
- bs = strtol(candidate_arch_machine_name, 0, 16);
- if (bs == 0)
- goto done;
-
- bytes_skipped = 0;
- do
- {
- lseek (fd, start+bs+bytes_skipped, SEEK_SET);
- if ((c = read (fd, buf, 8192)) <= 0)
- break;
- lseek (fd, start+bytes_skipped, SEEK_SET);
- if (write (fd, buf, c) < 0)
- goto bail;
- bytes_skipped += c;
- }
- while (c > 0);
- lseek (fd, start+bytes_skipped, SEEK_SET);
-
- done:
- free (buf);
- return FcTrue;
-
- bail:
- free (buf);
- return FcFalse;