summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'base/gp_unix.c')
-rw-r--r--base/gp_unix.c66
1 files changed, 65 insertions, 1 deletions
diff --git a/base/gp_unix.c b/base/gp_unix.c
index ce4fa057..bd2745f9 100644
--- a/base/gp_unix.c
+++ b/base/gp_unix.c
@@ -16,6 +16,9 @@
/* Unix-specific routines for Ghostscript */
+#ifdef __MINGW32__
+# include "windows_.h"
+#endif
#include "pipe_.h"
#include "string_.h"
#include "time_.h"
@@ -353,7 +356,11 @@ void *gp_enumerate_fonts_init(gs_memory_t *mem)
*/
code = 0;
while ((dirstr = FcStrListNext(fdirlist)) != NULL && code >= 0) {
- code = gs_add_control_path(mem, gs_permit_file_reading, (char *)dirstr);
+ char dirstr2[gp_file_name_sizeof];
+ dirstr2[0] = '\0';
+ strncat(dirstr2, (char *)dirstr, gp_file_name_sizeof - 2);
+ strncat(dirstr2, "/", gp_file_name_sizeof - 1);
+ code = gs_add_control_path(mem, gs_permit_file_reading, (char *)dirstr2);
}
FcStrListDone(fdirlist);
if (code < 0) {
@@ -370,6 +377,12 @@ void *gp_enumerate_fonts_init(gs_memory_t *mem)
os = FcObjectSetBuild(FC_FILE, FC_OUTLINE,
FC_FAMILY, FC_WEIGHT, FC_SLANT,
NULL);
+ /* We free the data allocated by FcFontList() when
+ gp_enumerate_fonts_free() calls FcFontSetDestroy(), but FcFontSetDestroy()
+ has been seen to leak blocks according to valgrind and asan. E.g. this can
+ be seen by running:
+ ./sanbin/gs -dNODISPLAY -dBATCH -dNOPAUSE -c "/A_Font findfont"
+ */
state->font_list = FcFontList(0, pat, os);
FcPatternDestroy(pat);
FcObjectSetDestroy(os);
@@ -466,3 +479,54 @@ void gp_enumerate_fonts_free(void *enum_state)
}
#endif
}
+
+/* A function to decode the next codepoint of the supplied args from the
+ * local windows codepage, or -1 for EOF.
+ * (copied from gp_win32.c)
+ */
+
+#ifdef __MINGW32__
+int
+gp_local_arg_encoding_get_codepoint(FILE *file, const char **astr)
+{
+ int len;
+ int c;
+ char arg[3];
+ wchar_t unicode[2];
+ char utf8[4];
+
+ if (file) {
+ c = fgetc(file);
+ if (c == EOF)
+ return EOF;
+ } else if (**astr) {
+ c = *(*astr)++;
+ if (c == 0)
+ return EOF;
+ } else {
+ return EOF;
+ }
+
+ arg[0] = c;
+ if (IsDBCSLeadByte(c)) {
+ if (file) {
+ c = fgetc(file);
+ if (c == EOF)
+ return EOF;
+ } else if (**astr) {
+ c = *(*astr)++;
+ if (c == 0)
+ return EOF;
+ }
+ arg[1] = c;
+ len = 2;
+ } else {
+ len = 1;
+ }
+
+ /* Convert the string (unterminated in, unterminated out) */
+ len = MultiByteToWideChar(CP_ACP, 0, arg, len, unicode, 2);
+
+ return unicode[0];
+}
+#endif