summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-06-26 17:47:29 +0100
committerRobin Watts <robin.watts@artifex.com>2015-06-29 12:14:39 +0100
commit074060eaf09044836c084453c4752d4ae283fabc (patch)
treeaccbfa665f88fb7f1ed27b5f4b4f4f61a8201a85 /source
parent895b9cff172c28efdf2ec479b9f2fce1287acbc2 (diff)
downloadmupdf-074060eaf09044836c084453c4752d4ae283fabc.tar.xz
Add an fz_tempfile utility.
This will be required for the gprf work.
Diffstat (limited to 'source')
-rw-r--r--source/fitz/tempfile.c26
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;
+}