|
Packit |
352660 |
/*
|
|
Packit |
352660 |
* fontconfig/test/test-bz89617.c
|
|
Packit |
352660 |
*
|
|
Packit |
352660 |
* Copyright © 2000 Keith Packard
|
|
Packit |
352660 |
* Copyright © 2018 Akira TAGOH
|
|
Packit |
352660 |
*
|
|
Packit |
352660 |
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
Packit |
352660 |
* documentation for any purpose is hereby granted without fee, provided that
|
|
Packit |
352660 |
* the above copyright notice appear in all copies and that both that
|
|
Packit |
352660 |
* copyright notice and this permission notice appear in supporting
|
|
Packit |
352660 |
* documentation, and that the name of the author(s) not be used in
|
|
Packit |
352660 |
* advertising or publicity pertaining to distribution of the software without
|
|
Packit |
352660 |
* specific, written prior permission. The authors make no
|
|
Packit |
352660 |
* representations about the suitability of this software for any purpose. It
|
|
Packit |
352660 |
* is provided "as is" without express or implied warranty.
|
|
Packit |
352660 |
*
|
|
Packit |
352660 |
* THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
Packit |
352660 |
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
Packit |
352660 |
* EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
Packit |
352660 |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
Packit |
352660 |
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
Packit |
352660 |
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
Packit |
352660 |
* PERFORMANCE OF THIS SOFTWARE.
|
|
Packit |
352660 |
*/
|
|
Packit |
352660 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
352660 |
#include "config.h"
|
|
Packit |
352660 |
#endif
|
|
Packit |
352660 |
#include <stdlib.h>
|
|
Packit |
352660 |
#include <dirent.h>
|
|
Packit |
352660 |
#ifndef HAVE_STRUCT_DIRENT_D_TYPE
|
|
Packit |
352660 |
#include <sys/types.h>
|
|
Packit |
352660 |
#include <sys/stat.h>
|
|
Packit |
352660 |
#include <unistd.h>
|
|
Packit |
352660 |
#endif
|
|
Packit |
352660 |
#include "fcstr.c"
|
|
Packit |
352660 |
#undef FcConfigBuildFonts
|
|
Packit |
352660 |
#undef FcConfigCreate
|
|
Packit |
352660 |
#undef FcConfigGetCurrent
|
|
Packit |
352660 |
#undef FcConfigParseAndLoadFromMemory
|
|
Packit |
352660 |
#undef FcConfigUptoDate
|
|
Packit |
352660 |
#undef FcFontList
|
|
Packit |
352660 |
#undef FcInitReinitialize
|
|
Packit |
352660 |
#undef FcPatternCreate
|
|
Packit |
352660 |
#undef FcPatternDestroy
|
|
Packit |
352660 |
#include <fontconfig/fontconfig.h>
|
|
Packit |
352660 |
|
|
Packit |
352660 |
#ifdef HAVE_MKDTEMP
|
|
Packit |
352660 |
#define fc_mkdtemp mkdtemp
|
|
Packit |
352660 |
#else
|
|
Packit |
352660 |
char *
|
|
Packit |
352660 |
fc_mkdtemp (char *template)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
if (!mktemp (template) || mkdir (template, 0700))
|
|
Packit |
352660 |
return NULL;
|
|
Packit |
352660 |
|
|
Packit |
352660 |
return template;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
#endif
|
|
Packit |
352660 |
|
|
Packit |
352660 |
FcBool
|
|
Packit |
352660 |
mkdir_p (const char *dir)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
char *parent;
|
|
Packit |
352660 |
FcBool ret;
|
|
Packit |
352660 |
|
|
Packit |
352660 |
if (strlen (dir) == 0)
|
|
Packit |
352660 |
return FcFalse;
|
|
Packit |
352660 |
parent = (char *) FcStrDirname ((const FcChar8 *) dir);
|
|
Packit |
352660 |
if (!parent)
|
|
Packit |
352660 |
return FcFalse;
|
|
Packit |
352660 |
if (access (parent, F_OK) == 0)
|
|
Packit |
352660 |
ret = mkdir (dir, 0755) == 0 && chmod (dir, 0755) == 0;
|
|
Packit |
352660 |
else if (access (parent, F_OK) == -1)
|
|
Packit |
352660 |
ret = mkdir_p (parent) && (mkdir (dir, 0755) == 0) && chmod (dir, 0755) == 0;
|
|
Packit |
352660 |
else
|
|
Packit |
352660 |
ret = FcFalse;
|
|
Packit |
352660 |
free (parent);
|
|
Packit |
352660 |
|
|
Packit |
352660 |
return ret;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
|
|
Packit |
352660 |
FcBool
|
|
Packit |
352660 |
unlink_dirs (const char *dir)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
DIR *d = opendir (dir);
|
|
Packit |
352660 |
struct dirent *e;
|
|
Packit |
352660 |
size_t len = strlen (dir);
|
|
Packit |
352660 |
char *n = NULL;
|
|
Packit |
352660 |
FcBool ret = FcTrue;
|
|
Packit |
352660 |
#ifndef HAVE_STRUCT_DIRENT_D_TYPE
|
|
Packit |
352660 |
struct stat statb;
|
|
Packit |
352660 |
#endif
|
|
Packit |
352660 |
|
|
Packit |
352660 |
if (!d)
|
|
Packit |
352660 |
return FcFalse;
|
|
Packit |
352660 |
while ((e = readdir (d)) != NULL)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
size_t l;
|
|
Packit |
352660 |
|
|
Packit |
352660 |
if (strcmp (e->d_name, ".") == 0 ||
|
|
Packit |
352660 |
strcmp (e->d_name, "..") == 0)
|
|
Packit |
352660 |
continue;
|
|
Packit |
352660 |
l = strlen (e->d_name) + 1;
|
|
Packit |
352660 |
if (n)
|
|
Packit |
352660 |
free (n);
|
|
Packit |
352660 |
n = malloc (l + len + 1);
|
|
Packit |
352660 |
if (!n)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
ret = FcFalse;
|
|
Packit |
352660 |
break;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
strcpy (n, dir);
|
|
Packit |
352660 |
n[len] = FC_DIR_SEPARATOR;
|
|
Packit |
352660 |
strcpy (&n[len + 1], e->d_name);
|
|
Packit |
352660 |
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
|
|
Packit |
352660 |
if (e->d_type == DT_DIR)
|
|
Packit |
352660 |
#else
|
|
Packit |
352660 |
if (stat (n, &statb) == -1)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
fprintf (stderr, "E: %s\n", n);
|
|
Packit |
352660 |
ret = FcFalse;
|
|
Packit |
352660 |
break;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
if (S_ISDIR (statb.st_mode))
|
|
Packit |
352660 |
#endif
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
if (!unlink_dirs (n))
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
fprintf (stderr, "E: %s\n", n);
|
|
Packit |
352660 |
ret = FcFalse;
|
|
Packit |
352660 |
break;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
else
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
if (unlink (n) == -1)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
fprintf (stderr, "E: %s\n", n);
|
|
Packit |
352660 |
ret = FcFalse;
|
|
Packit |
352660 |
break;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
if (n)
|
|
Packit |
352660 |
free (n);
|
|
Packit |
352660 |
closedir (d);
|
|
Packit |
352660 |
|
|
Packit |
352660 |
if (rmdir (dir) == -1)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
fprintf (stderr, "E: %s\n", dir);
|
|
Packit |
352660 |
return FcFalse;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
|
|
Packit |
352660 |
return ret;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
|
|
Packit |
352660 |
FcChar8 *
|
|
Packit |
352660 |
FcLangNormalize (const FcChar8 *lang)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
return NULL;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
|
|
Packit |
352660 |
FcChar8 *
|
|
Packit |
352660 |
FcConfigHome (void)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
return NULL;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
|
|
Packit |
352660 |
int
|
|
Packit |
352660 |
main (void)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
FcChar8 *fontdir = NULL, *cachedir = NULL, *fontname;
|
|
Packit |
352660 |
char *basedir, template[512] = "/tmp/bz106632-XXXXXX";
|
|
Packit |
352660 |
char cmd[512];
|
|
Packit |
352660 |
FcConfig *config;
|
|
Packit |
352660 |
const FcChar8 *tconf = "<fontconfig>\n"
|
|
Packit |
352660 |
" <dir>%s</dir>\n"
|
|
Packit |
352660 |
" <cachedir>%s</cachedir>\n"
|
|
Packit |
352660 |
"</fontconfig>\n";
|
|
Packit |
352660 |
char conf[1024];
|
|
Packit |
352660 |
int ret = 0;
|
|
Packit |
352660 |
FcFontSet *fs;
|
|
Packit |
352660 |
FcPattern *pat;
|
|
Packit |
352660 |
|
|
Packit |
352660 |
fprintf (stderr, "D: Creating tmp dir\n");
|
|
Packit |
352660 |
basedir = fc_mkdtemp (template);
|
|
Packit |
352660 |
if (!basedir)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
fprintf (stderr, "%s: %s\n", template, strerror (errno));
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
fontdir = FcStrBuildFilename (basedir, "fonts", NULL);
|
|
Packit |
352660 |
cachedir = FcStrBuildFilename (basedir, "cache", NULL);
|
|
Packit |
352660 |
fprintf (stderr, "D: Creating %s\n", fontdir);
|
|
Packit |
352660 |
mkdir_p (fontdir);
|
|
Packit |
352660 |
fprintf (stderr, "D: Creating %s\n", cachedir);
|
|
Packit |
352660 |
mkdir_p (cachedir);
|
|
Packit |
352660 |
|
|
Packit |
352660 |
fprintf (stderr, "D: Copying %s to %s\n", FONTFILE, fontdir);
|
|
Packit Service |
85ca44 |
snprintf (cmd, 512, "sleep 1; cp -a %s %s; sleep 1", FONTFILE, fontdir);
|
|
Packit |
352660 |
system (cmd);
|
|
Packit |
352660 |
|
|
Packit |
352660 |
fprintf (stderr, "D: Loading a config\n");
|
|
Packit |
352660 |
snprintf (conf, 1024, tconf, fontdir, cachedir);
|
|
Packit |
352660 |
config = FcConfigCreate ();
|
|
Packit |
352660 |
if (!FcConfigParseAndLoadFromMemory (config, conf, FcTrue))
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
printf ("E: Unable to load config\n");
|
|
Packit |
352660 |
ret = 1;
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
if (!FcConfigBuildFonts (config))
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
printf ("E: unable to build fonts\n");
|
|
Packit |
352660 |
ret = 1;
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
fprintf (stderr, "D: Obtaining fonts information\n");
|
|
Packit |
352660 |
pat = FcPatternCreate ();
|
|
Packit |
352660 |
fs = FcFontList (config, pat, NULL);
|
|
Packit |
352660 |
FcPatternDestroy (pat);
|
|
Packit |
352660 |
if (!fs || fs->nfont != 1)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
printf ("E: Unexpected the number of fonts: %d\n", !fs ? -1 : fs->nfont);
|
|
Packit |
352660 |
ret = 1;
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
fprintf (stderr, "D: Removing %s\n", fontdir);
|
|
Packit Service |
85ca44 |
snprintf (cmd, 512, "sleep 1; rm -f %s%s*; sleep 1", fontdir, FC_DIR_SEPARATOR_S);
|
|
Packit |
352660 |
system (cmd);
|
|
Packit |
352660 |
fprintf (stderr, "D: Reinitializing\n");
|
|
Packit Service |
85ca44 |
if (FcConfigUptoDate (config))
|
|
Packit |
4a86d3 |
{
|
|
Packit Service |
85ca44 |
fprintf (stderr, "E: Config reports up-to-date\n");
|
|
Packit Service |
3d8e54 |
ret = 2;
|
|
Packit |
4a86d3 |
goto bail;
|
|
Packit |
4a86d3 |
}
|
|
Packit Service |
85ca44 |
if (!FcInitReinitialize ())
|
|
Packit Service |
85ca44 |
{
|
|
Packit Service |
85ca44 |
fprintf (stderr, "E: Unable to reinitialize\n");
|
|
Packit Service |
85ca44 |
ret = 3;
|
|
Packit Service |
85ca44 |
goto bail;
|
|
Packit Service |
85ca44 |
}
|
|
Packit |
352660 |
if (FcConfigGetCurrent () == config)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
fprintf (stderr, "E: config wasn't reloaded\n");
|
|
Packit |
352660 |
ret = 3;
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
config = FcConfigCreate ();
|
|
Packit |
352660 |
if (!FcConfigParseAndLoadFromMemory (config, conf, FcTrue))
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
printf ("E: Unable to load config again\n");
|
|
Packit |
352660 |
ret = 4;
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
if (!FcConfigBuildFonts (config))
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
printf ("E: unable to build fonts again\n");
|
|
Packit |
352660 |
ret = 5;
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
fprintf (stderr, "D: Obtaining fonts information again\n");
|
|
Packit |
352660 |
pat = FcPatternCreate ();
|
|
Packit |
352660 |
fs = FcFontList (config, pat, NULL);
|
|
Packit |
352660 |
FcPatternDestroy (pat);
|
|
Packit |
352660 |
if (!fs || fs->nfont != 0)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
printf ("E: Unexpected the number of fonts: %d\n", !fs ? -1 : fs->nfont);
|
|
Packit |
352660 |
ret = 1;
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
fprintf (stderr, "D: Copying %s to %s\n", FONTFILE, fontdir);
|
|
Packit Service |
85ca44 |
snprintf (cmd, 512, "sleep 1; cp -a %s %s; sleep 1", FONTFILE, fontdir);
|
|
Packit |
352660 |
system (cmd);
|
|
Packit |
352660 |
fprintf (stderr, "D: Reinitializing\n");
|
|
Packit Service |
85ca44 |
if (FcConfigUptoDate (config))
|
|
Packit Service |
85ca44 |
{
|
|
Packit Service |
85ca44 |
fprintf (stderr, "E: Config up-to-date after addition\n");
|
|
Packit Service |
85ca44 |
ret = 3;
|
|
Packit Service |
85ca44 |
goto bail;
|
|
Packit Service |
85ca44 |
}
|
|
Packit Service |
85ca44 |
if (!FcInitReinitialize ())
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
fprintf (stderr, "E: Unable to reinitialize\n");
|
|
Packit |
352660 |
ret = 2;
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
if (FcConfigGetCurrent () == config)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
fprintf (stderr, "E: config wasn't reloaded\n");
|
|
Packit |
352660 |
ret = 3;
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
config = FcConfigCreate ();
|
|
Packit |
352660 |
if (!FcConfigParseAndLoadFromMemory (config, conf, FcTrue))
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
printf ("E: Unable to load config again\n");
|
|
Packit |
352660 |
ret = 4;
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
if (!FcConfigBuildFonts (config))
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
printf ("E: unable to build fonts again\n");
|
|
Packit |
352660 |
ret = 5;
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
fprintf (stderr, "D: Obtaining fonts information\n");
|
|
Packit |
352660 |
pat = FcPatternCreate ();
|
|
Packit |
352660 |
fs = FcFontList (config, pat, NULL);
|
|
Packit |
352660 |
FcPatternDestroy (pat);
|
|
Packit |
352660 |
if (!fs || fs->nfont != 1)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
printf ("E: Unexpected the number of fonts: %d\n", !fs ? -1 : fs->nfont);
|
|
Packit |
352660 |
ret = 1;
|
|
Packit |
352660 |
goto bail;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
|
|
Packit |
352660 |
bail:
|
|
Packit |
352660 |
fprintf (stderr, "Cleaning up\n");
|
|
Packit |
352660 |
unlink_dirs (basedir);
|
|
Packit |
352660 |
if (fontdir)
|
|
Packit |
352660 |
FcStrFree (fontdir);
|
|
Packit |
352660 |
if (cachedir)
|
|
Packit |
352660 |
FcStrFree (cachedir);
|
|
Packit |
352660 |
|
|
Packit |
352660 |
return ret;
|
|
Packit |
352660 |
}
|