fc-cache: improvement of the fix for Bug#39914.

Use sizeof() instead of strlen() and use stdio.
This commit is contained in:
Akira TAGOH 2012-03-22 12:36:34 +09:00
parent 4f7f3bf9f7
commit 1db3e9cdd8
1 changed files with 7 additions and 6 deletions

View File

@ -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;