#define ENDIAN_TEST 0x12345678
#define MACHINE_SIGNATURE_SIZE 9 + 5*20 + 1
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
static int
FcDirCacheOpen (const FcChar8 * dir);
if (stat ((char *) cache_file, &cache_stat) < 0)
return;
- cache->fd = open ((char *) cache_file, O_RDONLY);
+ cache->fd = open ((char *) cache_file, O_RDONLY | O_BINARY);
if (cache->fd == -1)
return;
if (!FcAtomicLock (atomic))
goto bail1;
- fd = open ((char *) FcAtomicNewFile(atomic), O_RDWR | O_CREAT,
+ fd = open ((char *) FcAtomicNewFile(atomic), O_RDWR | O_CREAT | O_BINARY,
S_IRUSR | S_IWUSR);
if (fd == -1)
goto bail2;
FcCacheWriteString (fd, FC_GLOBAL_MAGIC_COOKIE);
- fd_orig = open ((char *) FcAtomicOrigFile(atomic), O_RDONLY);
+ fd_orig = open ((char *) FcAtomicOrigFile(atomic), O_RDONLY | O_BINARY);
current_arch_machine_name = FcCacheMachineSignature ();
if (fd_orig == -1)
loc = 0;
lseek (fd, 0, SEEK_SET); lseek (fd_orig, 0, SEEK_SET);
+ FcCacheSkipString (fd); FcCacheSkipString (fd_orig);
do
{
int b = 8192;
fd = FcDirCacheOpen (dir);
if (fd < 0)
- goto bail;
+ return FcFalse;
if (fstat (fd, &file_stat) < 0)
goto bail;
return FcFalse;
/* First remove normal cache file. */
- if (stat ((char *) cache_file, &cache_stat) == 0 &&
- unlink ((char *)cache_file) != 0)
- goto bail;
+ if (stat ((char *) cache_file, &cache_stat) == 0)
+ unlink ((char *)cache_file);
/* Next remove any applicable hashed files. */
fd = -1; collisions = 0;
if (fd > 0)
close (fd);
- fd = open(cache_hashed, O_RDONLY);
+ fd = open(cache_hashed, O_RDONLY | O_BINARY);
if (fd == -1)
{
FcStrFree ((FcChar8 *)cache_file);
char name_buf[FC_MAX_FILE_LEN];
struct stat dir_stat;
- cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
- if (!cache_file)
+ if (stat ((char *)dir, &dir_stat) == -1)
return -1;
- fd = open(cache_file, O_RDONLY);
- if (fd != -1)
- return fd;
-
- if (stat ((char *)dir, &dir_stat) == -1)
+ cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
+ if (!cache_file)
return -1;
found = FcFalse;
do
{
- struct stat c;
- FcChar8 * name_buf_dir;
+ struct stat c;
+ FcChar8 *name_buf_dir;
+
+ if (fd >= 0)
+ close (fd);
cache_hashed = FcDirCacheHashName (cache_file, collisions++);
if (!cache_hashed)
return -1;
}
- if (fd > 0)
- close (fd);
- fd = open(cache_hashed, O_RDONLY);
+ fd = open(cache_hashed, O_RDONLY | O_BINARY);
FcStrFree ((FcChar8 *)cache_hashed);
if (fd == -1)
- {
- FcStrFree ((FcChar8 *)cache_file);
- return -1;
- }
- if (!FcCacheReadString (fd, name_buf, sizeof (name_buf)) || !strlen(name_buf))
- goto bail;
+ break;
+ if (!FcCacheReadString (fd, name_buf, sizeof (name_buf)) ||
+ !strlen(name_buf))
+ break;
name_buf_dir = FcStrDirname ((FcChar8 *)name_buf);
if (stat ((char *)name_buf_dir, &c) == -1)
FcStrFree (name_buf_dir);
found = (c.st_ino == dir_stat.st_ino) && (c.st_dev == dir_stat.st_dev);
} while (!found);
- FcStrFree ((FcChar8 *)cache_file);
- return fd;
- bail:
+ if (!found || fd < 0)
+ {
+ if (fd >= 0)
+ close (fd);
+ fd = open(cache_file, O_RDONLY | O_BINARY);
+ }
+
FcStrFree ((FcChar8 *)cache_file);
- close (fd);
- return -1;
+ return fd;
}
/* read serialized state from the cache file */
if (fd > 0)
close (fd);
- fd = open(cache_hashed, O_RDONLY);
+ fd = open(cache_hashed, O_RDONLY | O_BINARY);
if (fd == -1)
break;
if(!FcCacheReadString (fd, name_buf, sizeof (name_buf)) || !strlen(name_buf))
{
close (fd);
- break;
+ continue;
}
close (fd);
if (strcmp (name_buf, cache_file) != 0)
continue;
- } while (0);
+
+ break;
+ } while (1);
current_dir_block = FcDirCacheProduce (set, &metadata);
FcAtomicDestroy (atomic);
atomic = FcAtomicCreate ((FcChar8 *)cache_file);
- fd_orig = open (cache_file, O_RDONLY);
+ fd_orig = open (cache_file, O_RDONLY | O_BINARY);
if (fd_orig == -1)
- fd_orig = open((char *)FcAtomicOrigFile (atomic), O_RDONLY);
+ fd_orig = open((char *)FcAtomicOrigFile (atomic), O_RDONLY | O_BINARY);
- fd = open((char *)FcAtomicNewFile (atomic), O_RDWR | O_CREAT, 0666);
+ fd = open((char *)FcAtomicNewFile (atomic), O_RDWR | O_CREAT | O_BINARY, 0666);
if (fd == -1)
goto bail2;
}
/* In all cases, try opening the real location of the cache file first. */
/* (even if that's not atomic.) */
- fd_orig = open (cache_file, O_RDONLY);
+ fd_orig = open (cache_file, O_RDONLY | O_BINARY);
if (fd_orig == -1)
- fd_orig = open((char *)FcAtomicOrigFile (atomic), O_RDONLY);
+ fd_orig = open((char *)FcAtomicOrigFile (atomic), O_RDONLY | O_BINARY);
- fd = open((char *)FcAtomicNewFile (atomic), O_RDWR | O_CREAT, 0666);
+ fd = open((char *)FcAtomicNewFile (atomic), O_RDWR | O_CREAT | O_BINARY, 0666);
if (fd == -1)
goto bail3;
if (current_arch_start < 0)
{
off_t i = lseek(fd_orig, 0, SEEK_END);
- if (i < strlen (FC_GLOBAL_MAGIC_COOKIE)+1)
- i = strlen (FC_GLOBAL_MAGIC_COOKIE)+1;
current_arch_start = FcCacheNextOffset (i);
}