summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkira TAGOH <akira@tagoh.org>2012-03-22 12:36:34 +0900
committerAkira TAGOH <akira@tagoh.org>2012-03-22 12:36:34 +0900
commit1db3e9cdd8bc7408e630934cfc8deda7798b8970 (patch)
treeb7f78ffdaa2eaaa80869e4f308d5c43328f908f0
parent4f7f3bf9f78843be5b39eb64acfeb02ffcd8e3a4 (diff)
fc-cache: improvement of the fix for Bug#39914.
Use sizeof() instead of strlen() and use stdio.
-rw-r--r--fc-cache/fc-cache.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c
index 10bbea5b..24bb2ec9 100644
--- a/fc-cache/fc-cache.c
+++ b/fc-cache/fc-cache.c
@@ -131,18 +131,16 @@ create_tag_file (FcConfig *config, FcBool verbose)
FcChar8 *cache_dir = NULL;
FcStrList *list;
int fd;
+ FILE *fp;
FcAtomic *atomic;
static const FcChar8 cache_tag_contents[] =
"Signature: 8a477f597d28d172789f06886806bc55\n"
"# This file is a cache directory tag created by fontconfig.\n"
"# For information about cache directory tags, see:\n"
"# http://www.brynosaurus.com/cachedir/\n";
- static size_t cache_tag_contents_size = 0;
+ static size_t cache_tag_contents_size = sizeof (cache_tag_contents) - 1;
FcBool ret = FcTrue;
- if (cache_tag_contents_size == 0)
- cache_tag_contents_size = strlen((char *)cache_tag_contents);
-
list = FcConfigGetCacheDirs(config);
if (!list)
return FcFalse;
@@ -165,9 +163,12 @@ create_tag_file (FcConfig *config, FcBool verbose)
fd = open((char *)FcAtomicNewFile (atomic), O_RDWR | O_CREAT, 0644);
if (fd == -1)
goto bail3;
+ fp = fdopen(fd, "wb");
+ if (fp == NULL)
+ goto bail3;
- write(fd, cache_tag_contents, cache_tag_contents_size);
- close(fd);
+ fwrite(cache_tag_contents, cache_tag_contents_size, sizeof (FcChar8), fp);
+ fclose(fp);
if (!FcAtomicReplaceOrig(atomic))
goto bail3;