From 722ff826ea46ef49f57b927435d320c67ae37037 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 24 Apr 2017 16:17:15 +0200 Subject: Ensure we can compile as -pedantic -std=c99. --- source/fitz/tempfile.c | 54 ++++++-------------------------------------------- 1 file changed, 6 insertions(+), 48 deletions(-) (limited to 'source/fitz/tempfile.c') diff --git a/source/fitz/tempfile.c b/source/fitz/tempfile.c index 7c2bb1ff..8465d61e 100644 --- a/source/fitz/tempfile.c +++ b/source/fitz/tempfile.c @@ -7,54 +7,12 @@ * if required. */ -#include -#include -#include /* for tempnam */ +#include -/* 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 *fz_tempfilename(fz_context *ctx, const char *base, const char *dir) { - char *tmp; - char *ret; - -#ifdef USE_HINT_FOR_DIR - char *hintpath; - size_t 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); - - /* 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; + char *p = tmpnam(NULL); + if (!p) + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot generate temporary file name"); + return fz_strdup(ctx, p); } -- cgit v1.2.3