summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Lam <plam@MIT.EDU>2006-02-09 18:44:14 +0000
committerPatrick Lam <plam@MIT.EDU>2006-02-09 18:44:14 +0000
commit879af7060b24c6d57eb29cf6cfe2f6bb04589261 (patch)
tree26a5653d1e9eb1d0932054047125278a6aa2a8ee
parentc7490074c57da387904cecfdf60595713c7bb89e (diff)
Define and pass O_BINARY to open if appropriate, for those platforms that
need it. Reported by Doodle.
-rw-r--r--ChangeLog7
-rw-r--r--src/fccache.c30
2 files changed, 21 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 6abd791a..d5224a79 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,9 @@
2006-02-09 Patrick Lam <plam@mit.edu>
- * src/fccache.c (FcDirCacheValid, FcDirCacheWrite):
+ * src/fccache.c (FcGlobalCacheLoad, FcGlobalCacheSave,
+ FcDirCacheUnlink, FcDirCacheOpen, FcDirCacheWrite):
- Fix attempt to close -1.
- Don't unboundedly grow bad caches (reported by fcrozat).
+ Define and pass O_BINARY to open if appropriate, for those
+ platforms that need it. Reported by Doodle.
2006-02-09 Patrick Lam <plam@mit.edu>
* src/fccharset.c (FcCharSetNeededBytes, FcCharSetSerialize,
diff --git a/src/fccache.c b/src/fccache.c
index 69b08cb1..0ec41173 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -36,6 +36,10 @@
#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);
@@ -187,7 +191,7 @@ FcGlobalCacheLoad (FcGlobalCache *cache,
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;
@@ -427,13 +431,13 @@ FcGlobalCacheSave (FcGlobalCache *cache,
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)
@@ -804,7 +808,7 @@ FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config)
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);
@@ -1019,7 +1023,7 @@ FcDirCacheOpen (const FcChar8 *dir)
if (!cache_file)
return -1;
- fd = open(cache_file, O_RDONLY);
+ fd = open(cache_file, O_RDONLY | O_BINARY);
if (fd != -1)
return fd;
@@ -1041,7 +1045,7 @@ FcDirCacheOpen (const FcChar8 *dir)
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)
@@ -1233,7 +1237,7 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
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))
@@ -1267,22 +1271,22 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
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;