Skip to content

Instantly share code, notes, and snippets.

Created April 5, 2016 00:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/5117f5ac08ae50f38e12ddebd1fb2e41 to your computer and use it in GitHub Desktop.
fontconfig patch try 1
From b10cb30103826a85c3e4671ba6d2b60212e42a7c Mon Sep 17 00:00:00 2001
Date: Tue, 5 Apr 2016 02:43:51 +0200
Subject: [PATCH 1/1] fix test 1
---
src/fccache.c | 19 ++++++++-----------
src/fcdir.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/fcint.h | 6 ++++--
3 files changed, 64 insertions(+), 14 deletions(-)
diff --git a/src/fccache.c b/src/fccache.c
index b681a5e..f172a6b 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -132,7 +132,7 @@ FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config)
list = FcStrListCreate (config->cacheDirs);
if (!list)
return FcFalse;
-
+
while ((cache_dir = FcStrListNext (list)))
{
if (sysroot)
@@ -208,7 +208,7 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
list = FcStrListCreate (config->cacheDirs);
if (!list)
return FcFalse;
-
+
while ((cache_dir = FcStrListNext (list)))
{
FcChar8 *cache_hashed;
@@ -590,25 +590,22 @@ FcCacheTimeValid (FcConfig *config, FcCache *cache, struct stat *dir_stat)
static FcBool
FcCacheDirsValid (FcConfig *config, FcCache *cache)
{
- FcStrSet *dirs = FcStrSetCreateEx (FCSS_GROW_BY_64);
FcBool ret = FcFalse;
const FcChar8 *sysroot = FcConfigGetSysRoot (config);
FcChar8 *d;
+ size_t numDirs = 0;
- if (!dirs)
- goto bail;
if (sysroot)
d = FcStrBuildFilename (sysroot, FcCacheDir (cache), NULL);
else
d = FcStrdup (FcCacheDir (cache));
- if (!FcDirScanOnly (dirs, d, config))
+ if (!FcDirScanConfigNum (d, &numDirs))
goto bail1;
- ret = cache->dirs_count == dirs->num;
+ ret = cache->dirs_count == numDirs;
if (FcDebug () & FC_DBG_CACHE)
- printf ("%s: cache: %d, fs: %d\n", d, cache->dirs_count, dirs->num);
+ printf ("%s: cache: %d, fs: %d\n", d, cache->dirs_count, numDirs);
bail1:
- FcStrSetDestroy (dirs);
FcStrFree (d);
bail:
return ret;
@@ -700,7 +697,7 @@ FcDirCacheMapFd (FcConfig *config, int fd, struct stat *fd_stat, struct stat *di
/* Mark allocated caches so they're freed rather than unmapped */
if (allocated)
cache->magic = FC_CACHE_MAGIC_ALLOC;
-
+
return cache;
}
@@ -1275,7 +1272,7 @@ FcCacheCopySet args1(const FcCache *c)
for (i = 0; i < old->nfont; i++)
{
FcPattern *font = FcFontSetFont (old, i);
-
+
FcPatternReference (font);
if (!FcFontSetAdd (new, font))
{
diff --git a/src/fcdir.c b/src/fcdir.c
index 81c98b6..70e901f 100644
--- a/src/fcdir.c
+++ b/src/fcdir.c
@@ -171,6 +171,57 @@ FcFileScanFontConfig (FcFontSet *set,
return ret;
}
+FcBool FcDirScanConfigNum (const FcChar8 *dir, size_t *numDirs) {
+ DIR *d;
+ struct dirent *e;
+ FcChar8 *file = 0;
+ FcChar8 *base;
+ FcBool ret = FcTrue;
+
+ if(!numDirs) {
+ ret = FcFalse;
+ goto bail;
+ }
+
+ /* freed below */
+ file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + FC_MAX_FILE_LEN + 1);
+ if (!file) {
+ ret = FcFalse;
+ goto bail;
+ }
+
+ strcpy ((char *) file, (char *) dir);
+ strcat ((char *) file, "/");
+ base = file + strlen ((char *) file);
+
+ if (FcDebug () & FC_DBG_SCAN)
+ printf ("\tScanning dir %s\n", dir);
+
+ d = opendir ((char *) dir);
+ if (!d) {
+ if (errno != ENOENT)
+ ret = FcFalse;
+ goto bail;
+ }
+
+ while ((e = readdir (d))) {
+ if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN) {
+ strcpy ((char *) base, (char *) e->d_name);
+ if (FcFileIsDir (file)) {
+ FcDirScanConfigNum(file, numDirs);
+ (*numDirs)++;
+ }
+ }
+ }
+ closedir (d);
+
+bail:
+ if (file)
+ free (file);
+
+ return ret;
+}
+
FcBool
FcFileScanConfig (FcFontSet *set,
FcStrSet *dirs,
@@ -266,7 +317,7 @@ FcDirScanConfig (FcFontSet *set,
if (FcDebug () & FC_DBG_SCAN)
printf ("\tScanning dir %s\n", dir);
-
+
d = opendir ((char *) dir);
if (!d)
{
diff --git a/src/fcint.h b/src/fcint.h
index ee6cc99..bf7af70 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -175,7 +175,7 @@ typedef struct _FcValueList {
} FcValueList;
#define FcValueListNext(vl) FcPointerMember(vl,next,FcValueList)
-
+
typedef int FcObject;
/* The 1024 is to leave some room for future added internal objects, such
@@ -214,7 +214,7 @@ struct _FcPattern {
FcFontSetFonts(fs)[i], \
FcPattern) : \
fs->fonts[i])
-
+
typedef enum _FcOp {
FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpRange, FcOpBool, FcOpCharSet, FcOpLangSet,
FcOpNil,
@@ -845,6 +845,8 @@ FcFileScanConfig (FcFontSet *set,
const FcChar8 *file,
FcConfig *config);
+FcPrivate FcBool FcDirScanConfigNum (const FcChar8 *dir, size_t *numDirs);
+
FcPrivate FcBool
FcDirScanConfig (FcFontSet *set,
FcStrSet *dirs,
--
2.8.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment