From 074060eaf09044836c084453c4752d4ae283fabc Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 26 Jun 2015 17:47:29 +0100 Subject: Add an fz_tempfile utility. This will be required for the gprf work. --- include/mupdf/fitz/output.h | 6 ++++++ platform/win32/libmupdf.vcproj | 4 ++++ source/fitz/tempfile.c | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 source/fitz/tempfile.c diff --git a/include/mupdf/fitz/output.h b/include/mupdf/fitz/output.h index 6291d37e..36d194f8 100644 --- a/include/mupdf/fitz/output.h +++ b/include/mupdf/fitz/output.h @@ -101,4 +101,10 @@ int fz_fprintf(fz_context *ctx, FILE *file, const char *fmt, ...); int fz_vsnprintf(char *buffer, int space, const char *fmt, va_list args); int fz_snprintf(char *buffer, int space, const char *fmt, ...); +/* + fz_tempfilename: Get a temporary filename based upon 'base'. + This must be freed. +*/ +char *fz_tempfilename(fz_context *ctx, const char *base); + #endif diff --git a/platform/win32/libmupdf.vcproj b/platform/win32/libmupdf.vcproj index 07ceb673..8e268f15 100644 --- a/platform/win32/libmupdf.vcproj +++ b/platform/win32/libmupdf.vcproj @@ -1009,6 +1009,10 @@ RelativePath="..\..\source\fitz\svg-device.c" > + + diff --git a/source/fitz/tempfile.c b/source/fitz/tempfile.c new file mode 100644 index 00000000..2115923e --- /dev/null +++ b/source/fitz/tempfile.c @@ -0,0 +1,26 @@ +#include "mupdf/fitz.h" + +/* Produce a (hopefully) unique temporary filename based upon a given + * 'base' name. + * + * Isolated into a file that can be modified on a per-platform basis + * if required. + */ + +char *fz_tempfilename(fz_context *ctx, const char *base) +{ + char *tmp = tempnam(".", base); + char *ret; + + if (tmp == NULL) + fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to construct temporary file name"); + ret = fz_strdup(ctx, tmp); + + /* The value returned from tempnam is allocated using malloc. + * We must therefore free it using free. Real, honest to God + * free, not Memento_free, or other wrapped versions. + */ +#undef free + (free)(tmp); + return ret; +} -- cgit v1.2.3