1 From 806fd4c2c5164d66d978b0a4c579c157e5cbe766 Mon Sep 17 00:00:00 2001
2 From: Akira TAGOH <akira@tagoh.org>
3 Date: Tue, 4 Sep 2018 09:08:37 +0000
4 Subject: [PATCH] Fix the issue that '~' wasn't extracted to the proper homedir
6 '~' in the filename was extracted to the home directory name in FcConfigFilename() though,
7 this behavior was broken by d1f48f11. this change fixes it back to the correct behavior.
9 https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/110
10 diff --git a/src/fccfg.c b/src/fccfg.c
11 index d7c48e8..4a53581 100644
14 @@ -2207,17 +2207,19 @@ FcConfigFilename (const FcChar8 *url)
19 - path = FcConfigGetPath ();
22 - for (p = path; *p; p++)
25 - file = FcConfigFileExists (*p, url);
28 + path = FcConfigGetPath ();
31 + for (p = path; *p; p++)
33 + file = FcConfigFileExists (*p, url);
37 + FcConfigFreePath (path);
39 - FcConfigFreePath (path);
43 diff --git a/test/Makefile.am b/test/Makefile.am
44 index 79bcede..9f4d48a 100644
45 --- a/test/Makefile.am
46 +++ b/test/Makefile.am
47 @@ -91,6 +91,22 @@ test_bz106632_CFLAGS = \
48 test_bz106632_LDADD = $(top_builddir)/src/libfontconfig.la
49 TESTS += test-bz106632
52 +check_PROGRAMS += test-issue110
53 +test_issue110_CFLAGS = \
55 + -I$(top_builddir)/src \
57 + -I$(top_srcdir)/src \
59 + -DFONTCONFIG_PATH='"$(BASECONFIGDIR)"' \
61 +test_issue110_LDADD = \
62 + $(top_builddir)/src/libfontconfig.la \
64 +TESTS += test-issue110
67 EXTRA_DIST=run-test.sh run-test-conf.sh $(TESTDATA) out.expected-long-family-names out.expected-no-long-family-names
69 CLEANFILES=out out1 out2 fonts.conf out.expected
70 diff --git a/test/test-issue110.c b/test/test-issue110.c
72 index 0000000..28a3bd2
74 +++ b/test/test-issue110.c
77 + * fontconfig/test/test-issue110.c
79 + * Copyright © 2000 Keith Packard
80 + * Copyright © 2018 Akira TAGOH
82 + * Permission to use, copy, modify, distribute, and sell this software and its
83 + * documentation for any purpose is hereby granted without fee, provided that
84 + * the above copyright notice appear in all copies and that both that
85 + * copyright notice and this permission notice appear in supporting
86 + * documentation, and that the name of the author(s) not be used in
87 + * advertising or publicity pertaining to distribution of the software without
88 + * specific, written prior permission. The authors make no
89 + * representations about the suitability of this software for any purpose. It
90 + * is provided "as is" without express or implied warranty.
92 + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
93 + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
94 + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
95 + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
96 + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
97 + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
98 + * PERFORMANCE OF THIS SOFTWARE.
100 +#ifdef HAVE_CONFIG_H
109 +#ifndef HAVE_STRUCT_DIRENT_D_TYPE
110 +#include <sys/types.h>
111 +#include <sys/stat.h>
113 +#include <fontconfig/fontconfig.h>
116 +# define FC_DIR_SEPARATOR '\\'
117 +# define FC_DIR_SEPARATOR_S "\\"
119 +# define FC_DIR_SEPARATOR '/'
120 +# define FC_DIR_SEPARATOR_S "/"
123 +extern FcChar8 *FcConfigRealFilename (FcConfig *, FcChar8 *);
126 +#define fc_mkdtemp mkdtemp
129 +fc_mkdtemp (char *template)
131 + if (!mktemp (template) || mkdir (template, 0700))
139 +mkdir_p (const char *dir)
144 + if (strlen (dir) == 0)
146 + parent = (char *) FcStrDirname ((const FcChar8 *) dir);
149 + if (access (parent, F_OK) == 0)
150 + ret = mkdir (dir, 0755) == 0 && chmod (dir, 0755) == 0;
151 + else if (access (parent, F_OK) == -1)
152 + ret = mkdir_p (parent) && (mkdir (dir, 0755) == 0) && chmod (dir, 0755) == 0;
161 +unlink_dirs (const char *dir)
163 + DIR *d = opendir (dir);
165 + size_t len = strlen (dir);
167 + FcBool ret = FcTrue;
168 +#ifndef HAVE_STRUCT_DIRENT_D_TYPE
174 + while ((e = readdir (d)) != NULL)
178 + if (strcmp (e->d_name, ".") == 0 ||
179 + strcmp (e->d_name, "..") == 0)
181 + l = strlen (e->d_name) + 1;
184 + n = malloc (l + len + 1);
191 + n[len] = FC_DIR_SEPARATOR;
192 + strcpy (&n[len + 1], e->d_name);
193 +#ifdef HAVE_STRUCT_DIRENT_D_TYPE
194 + if (e->d_type == DT_DIR)
196 + if (stat (n, &statb) == -1)
198 + fprintf (stderr, "E: %s\n", n);
202 + if (S_ISDIR (statb.st_mode))
205 + if (!unlink_dirs (n))
207 + fprintf (stderr, "E: %s\n", n);
214 + if (unlink (n) == -1)
216 + fprintf (stderr, "E: %s\n", n);
226 + if (rmdir (dir) == -1)
228 + fprintf (stderr, "E: %s\n", dir);
238 + FcConfig *cfg = FcConfigCreate ();
239 + char *basedir, template[512] = "/tmp/fc110-XXXXXX";
240 + char *sysroot, systempl[512] = "/tmp/fc110-XXXXXX";
242 + FcChar8 *ret = NULL;
248 + basedir = fc_mkdtemp (template);
251 + fprintf (stderr, "%s: %s\n", template, strerror (errno));
255 + sysroot = fc_mkdtemp (systempl);
258 + fprintf (stderr, "%s: %s\n", systempl, strerror (errno));
261 + fprintf (stderr, "D: Creating %s\n", basedir);
263 + setenv ("HOME", basedir, 1);
265 + s = FcStrBuildFilename (basedir, ".fonts.conf", NULL);
269 + fprintf (stderr, "D: Creating %s\n", s);
270 + if ((fp = fopen (s, "wb")) == NULL)
272 + fprintf (fp, "%s", s);
275 + fprintf (stderr, "D: Checking file path\n");
276 + ret = FcConfigRealFilename (cfg, "~/.fonts.conf");
280 + if (strcmp ((const char *) s, (const char *) ret) != 0)
284 + setenv ("FONTCONFIG_SYSROOT", sysroot, 1);
285 + fprintf (stderr, "D: Creating %s\n", sysroot);
288 + d = FcStrBuildFilename (sysroot, basedir, NULL);
289 + fprintf (stderr, "D: Creating %s\n", d);
292 + s = FcStrBuildFilename (sysroot, basedir, ".fonts.conf", NULL);
296 + fprintf (stderr, "D: Creating %s\n", s);
297 + if ((fp = fopen (s, "wb")) == NULL)
299 + fprintf (fp, "%s", s);
302 + fprintf (stderr, "D: Checking file path\n");
303 + ret = FcConfigRealFilename (cfg, "~/.fonts.conf");
307 + if (strcmp ((const char *) s, (const char *) ret) != 0)
311 + fprintf (stderr, "Cleaning up\n");
312 + unlink_dirs (basedir);