#include <sys/types.h>
#include <unistd.h>
#include "fcint.h"
+#include <unistd.h>
#define ENDIAN_TEST 0x12345678
-#define MACHINE_SIGNATURE_SIZE 9 + 5*19 + 1
+#define MACHINE_SIGNATURE_SIZE 9 + 5*20 + 1
static off_t
FcCacheSkipToArch (int fd, const char * arch);
void
FcGlobalCacheLoad (FcGlobalCache *cache,
FcStrSet *staleDirs,
- const FcChar8 *cache_file)
+ const FcChar8 *cache_file,
+ FcConfig *config)
{
char name_buf[8192];
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;
if (!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)
+ dir_stat.st_mtime > cache_stat.st_mtime ||
+ (config_time.set && cache_stat.st_mtime < config_time.time))
{
FcCache md;
return FcFalse;
}
-#define PAGESIZE 8192
/*
* Find the next presumably-mmapable offset after the supplied file
* position.
static int
FcCacheNextOffset(off_t w)
{
- if (w % PAGESIZE == 0)
+ static long pagesize = -1;
+ if (pagesize == -1)
+ pagesize = sysconf(_SC_PAGESIZE);
+ if (w % pagesize == 0)
return w;
else
- return ((w / PAGESIZE)+1)*PAGESIZE;
+ return ((w / pagesize)+1)*pagesize;
}
/* return the address of the segment for the provided arch,
* If the directory has been modified more recently than
* the cache file, the cache is not valid
*/
- if (dir_stat.st_mtime - file_stat.st_mtime > 0)
+ if (dir_stat.st_mtime > file_stat.st_mtime)
return FcFalse;
+
return FcTrue;
}
memset (metadata, 0, sizeof(FcCache));
FcFontSetNewBank();
- metadata->count = FcFontSetNeededBytes (set);
+ metadata->count = FcFontSetNeededBytes (set) +
+ FcFontSetNeededBytesAlign ();
metadata->magic = FC_CACHE_MAGIC;
metadata->bank = bank;
FcCacheMachineSignature ()
{
static char buf[MACHINE_SIGNATURE_SIZE];
- int magic = ENDIAN_TEST;
+ int32_t magic = ENDIAN_TEST;
char * m = (char *)&magic;
sprintf (buf, "%2x%2x%2x%2x "
"%4x %4x %4x %4x %4x %4x %4x %4x %4x %4x %4x %4x "
- "%4x %4x %4x %4x %4x %4x %4x\n",
+ "%4x %4x %4x %4x %4x %4x %4x %4x\n",
m[0], m[1], m[2], m[3],
(unsigned int)sizeof (char),
(unsigned int)sizeof (char *),
(unsigned int)sizeof (FcChar16),
(unsigned int)sizeof (FcCharLeaf),
(unsigned int)sizeof (FcChar32),
- (unsigned int)sizeof (FcCache));
+ (unsigned int)sizeof (FcCache),
+ (unsigned int)sysconf(_SC_PAGESIZE));
return buf;
}