version bumps
[dbus-free.git] / media-libs / fontconfig / files / fontconfig-2.13.1-proper_homedir.patch
blob19aee94ba9882b719cc6d8dffa19eb7b67934aa4
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
12 --- a/src/fccfg.c
13 +++ b/src/fccfg.c
14 @@ -2207,17 +2207,19 @@ FcConfigFilename (const FcChar8 *url)
15 else
16 file = 0;
19 - path = FcConfigGetPath ();
20 - if (!path)
21 - return NULL;
22 - for (p = path; *p; p++)
23 + else
25 - file = FcConfigFileExists (*p, url);
26 - if (file)
27 - break;
28 + path = FcConfigGetPath ();
29 + if (!path)
30 + return NULL;
31 + for (p = path; *p; p++)
32 + {
33 + file = FcConfigFileExists (*p, url);
34 + if (file)
35 + break;
36 + }
37 + FcConfigFreePath (path);
39 - FcConfigFreePath (path);
40 return file;
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
51 +if !ENABLE_SHARED
52 +check_PROGRAMS += test-issue110
53 +test_issue110_CFLAGS = \
54 + -I$(top_builddir) \
55 + -I$(top_builddir)/src \
56 + -I$(top_srcdir) \
57 + -I$(top_srcdir)/src \
58 + -DHAVE_CONFIG_H \
59 + -DFONTCONFIG_PATH='"$(BASECONFIGDIR)"' \
60 + $(NULL)
61 +test_issue110_LDADD = \
62 + $(top_builddir)/src/libfontconfig.la \
63 + $(NULL)
64 +TESTS += test-issue110
65 +endif
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
71 new file mode 100644
72 index 0000000..28a3bd2
73 --- /dev/null
74 +++ b/test/test-issue110.c
75 @@ -0,0 +1,245 @@
76 +/*
77 + * fontconfig/test/test-issue110.c
78 + *
79 + * Copyright © 2000 Keith Packard
80 + * Copyright © 2018 Akira TAGOH
81 + *
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.
91 + *
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.
99 + */
100 +#ifdef HAVE_CONFIG_H
101 +#include "config.h"
102 +#endif
103 +#include <stdio.h>
104 +#include <stdlib.h>
105 +#include <string.h>
106 +#include <dirent.h>
107 +#include <unistd.h>
108 +#include <errno.h>
109 +#ifndef HAVE_STRUCT_DIRENT_D_TYPE
110 +#include <sys/types.h>
111 +#include <sys/stat.h>
112 +#endif
113 +#include <fontconfig/fontconfig.h>
115 +#ifdef _WIN32
116 +# define FC_DIR_SEPARATOR '\\'
117 +# define FC_DIR_SEPARATOR_S "\\"
118 +#else
119 +# define FC_DIR_SEPARATOR '/'
120 +# define FC_DIR_SEPARATOR_S "/"
121 +#endif
123 +extern FcChar8 *FcConfigRealFilename (FcConfig *, FcChar8 *);
125 +#ifdef HAVE_MKDTEMP
126 +#define fc_mkdtemp mkdtemp
127 +#else
128 +char *
129 +fc_mkdtemp (char *template)
131 + if (!mktemp (template) || mkdir (template, 0700))
132 + return NULL;
134 + return template;
136 +#endif
138 +FcBool
139 +mkdir_p (const char *dir)
141 + char *parent;
142 + FcBool ret;
144 + if (strlen (dir) == 0)
145 + return FcFalse;
146 + parent = (char *) FcStrDirname ((const FcChar8 *) dir);
147 + if (!parent)
148 + return FcFalse;
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;
153 + else
154 + ret = FcFalse;
155 + free (parent);
157 + return ret;
160 +FcBool
161 +unlink_dirs (const char *dir)
163 + DIR *d = opendir (dir);
164 + struct dirent *e;
165 + size_t len = strlen (dir);
166 + char *n = NULL;
167 + FcBool ret = FcTrue;
168 +#ifndef HAVE_STRUCT_DIRENT_D_TYPE
169 + struct stat statb;
170 +#endif
172 + if (!d)
173 + return FcFalse;
174 + while ((e = readdir (d)) != NULL)
176 + size_t l;
178 + if (strcmp (e->d_name, ".") == 0 ||
179 + strcmp (e->d_name, "..") == 0)
180 + continue;
181 + l = strlen (e->d_name) + 1;
182 + if (n)
183 + free (n);
184 + n = malloc (l + len + 1);
185 + if (!n)
187 + ret = FcFalse;
188 + break;
190 + strcpy (n, dir);
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)
195 +#else
196 + if (stat (n, &statb) == -1)
198 + fprintf (stderr, "E: %s\n", n);
199 + ret = FcFalse;
200 + break;
202 + if (S_ISDIR (statb.st_mode))
203 +#endif
205 + if (!unlink_dirs (n))
207 + fprintf (stderr, "E: %s\n", n);
208 + ret = FcFalse;
209 + break;
212 + else
214 + if (unlink (n) == -1)
216 + fprintf (stderr, "E: %s\n", n);
217 + ret = FcFalse;
218 + break;
222 + if (n)
223 + free (n);
224 + closedir (d);
226 + if (rmdir (dir) == -1)
228 + fprintf (stderr, "E: %s\n", dir);
229 + return FcFalse;
232 + return ret;
235 +int
236 +main(void)
238 + FcConfig *cfg = FcConfigCreate ();
239 + char *basedir, template[512] = "/tmp/fc110-XXXXXX";
240 + char *sysroot, systempl[512] = "/tmp/fc110-XXXXXX";
241 + FcChar8 *d = NULL;
242 + FcChar8 *ret = NULL;
243 + FcChar8 *s = NULL;
244 + FILE *fp;
245 + int retval = 0;
247 + retval++;
248 + basedir = fc_mkdtemp (template);
249 + if (!basedir)
251 + fprintf (stderr, "%s: %s\n", template, strerror (errno));
252 + goto bail;
254 + retval++;
255 + sysroot = fc_mkdtemp (systempl);
256 + if (!sysroot)
258 + fprintf (stderr, "%s: %s\n", systempl, strerror (errno));
259 + goto bail;
261 + fprintf (stderr, "D: Creating %s\n", basedir);
262 + mkdir_p (basedir);
263 + setenv ("HOME", basedir, 1);
264 + retval++;
265 + s = FcStrBuildFilename (basedir, ".fonts.conf", NULL);
266 + if (!s)
267 + goto bail;
268 + retval++;
269 + fprintf (stderr, "D: Creating %s\n", s);
270 + if ((fp = fopen (s, "wb")) == NULL)
271 + goto bail;
272 + fprintf (fp, "%s", s);
273 + fclose (fp);
274 + retval++;
275 + fprintf (stderr, "D: Checking file path\n");
276 + ret = FcConfigRealFilename (cfg, "~/.fonts.conf");
277 + if (!ret)
278 + goto bail;
279 + retval++;
280 + if (strcmp ((const char *) s, (const char *) ret) != 0)
281 + goto bail;
282 + free (ret);
283 + free (s);
284 + setenv ("FONTCONFIG_SYSROOT", sysroot, 1);
285 + fprintf (stderr, "D: Creating %s\n", sysroot);
286 + mkdir_p (sysroot);
287 + retval++;
288 + d = FcStrBuildFilename (sysroot, basedir, NULL);
289 + fprintf (stderr, "D: Creating %s\n", d);
290 + mkdir_p (d);
291 + free (d);
292 + s = FcStrBuildFilename (sysroot, basedir, ".fonts.conf", NULL);
293 + if (!s)
294 + goto bail;
295 + retval++;
296 + fprintf (stderr, "D: Creating %s\n", s);
297 + if ((fp = fopen (s, "wb")) == NULL)
298 + goto bail;
299 + fprintf (fp, "%s", s);
300 + fclose (fp);
301 + retval++;
302 + fprintf (stderr, "D: Checking file path\n");
303 + ret = FcConfigRealFilename (cfg, "~/.fonts.conf");
304 + if (!ret)
305 + goto bail;
306 + retval++;
307 + if (strcmp ((const char *) s, (const char *) ret) != 0)
308 + goto bail;
309 + retval = 0;
310 +bail:
311 + fprintf (stderr, "Cleaning up\n");
312 + unlink_dirs (basedir);
313 + if (ret)
314 + free (ret);
315 + if (s)
316 + free (s);
318 + return retval;
322 2.18.0