summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-07-20 11:02:41 +0100
committerRobin Watts <robin.watts@artifex.com>2015-07-20 17:18:59 +0100
commit08cf4d8a9353b6bb938492cb9e7c3d1ba4aabf08 (patch)
tree705a39c9f3d5853e93384d7217ef2cdb9e08f4b1 /source
parent6d006a43d50bcbfc20cbb574c6953cfcfe906208 (diff)
downloadmupdf-08cf4d8a9353b6bb938492cb9e7c3d1ba4aabf08.tar.xz
Tweak fz_tempfile to include directory hint.
In android, we can't write to '.', and we don't have TMP defined. Therefore use the path of the supplied file as a hint.
Diffstat (limited to 'source')
-rw-r--r--source/fitz/tempfile.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/source/fitz/tempfile.c b/source/fitz/tempfile.c
index 2115923e..77c7c04a 100644
--- a/source/fitz/tempfile.c
+++ b/source/fitz/tempfile.c
@@ -1,17 +1,47 @@
#include "mupdf/fitz.h"
/* Produce a (hopefully) unique temporary filename based upon a given
- * 'base' name.
+ * 'base' name, with a 'hint' for where to create it.
*
* Isolated into a file that can be modified on a per-platform basis
* if required.
*/
-char *fz_tempfilename(fz_context *ctx, const char *base)
+/* For now, put temporary files with the hint. */
+#define USE_HINT_FOR_DIR
+
+#if defined(_WIN32) || defined(_WIN64)
+#define DIRSEP '\\'
+#else
+#define DIRSEP '/'
+#endif
+
+char *fz_tempfilename(fz_context *ctx, const char *base, const char *hint)
{
- char *tmp = tempnam(".", base);
+ char *tmp;
char *ret;
+#ifdef USE_HINT_FOR_DIR
+ char *hintpath;
+ int hintlen;
+
+ hintlen = strlen(hint);
+ hintpath = fz_malloc(ctx, 1 + hintlen);
+ if (hint == NULL)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to construct temporary file name");
+
+ while (hintlen > 0 && hint[hintlen-1] != DIRSEP)
+ hintlen--;
+
+ if (hintlen > 0)
+ memcpy(hintpath, hint, hintlen);
+ hintpath[hintlen] = 0;
+ tmp = tempnam(hintlen > 0 ? hintpath : ".", base);
+ fz_free(ctx, hintpath);
+#else
+ tmp = tempnam(".", base);
+#endif
+
if (tmp == NULL)
fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to construct temporary file name");
ret = fz_strdup(ctx, tmp);