summaryrefslogtreecommitdiff
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
parent895b9cff172c28efdf2ec479b9f2fce1287acbc2 (diff)
downloadmupdf-074060eaf09044836c084453c4752d4ae283fabc.tar.xz
Add an fz_tempfile utility.
This will be required for the gprf work.
-rw-r--r--include/mupdf/fitz/output.h6
-rw-r--r--platform/win32/libmupdf.vcproj4
-rw-r--r--source/fitz/tempfile.c26
3 files changed, 36 insertions, 0 deletions
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
@@ -1010,6 +1010,10 @@
>
</File>
<File
+ RelativePath="..\..\source\fitz\tempfile.c"
+ >
+ </File>
+ <File
RelativePath="..\..\source\fitz\test-device.c"
>
</File>
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;
+}