diff options
Diffstat (limited to 'source/fitz/tempfile.c')
-rw-r--r-- | source/fitz/tempfile.c | 26 |
1 files changed, 26 insertions, 0 deletions
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; +} |