From 54ab3137d5c417a6060abf1ae85a31abaf23fe32 Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Sun, 29 Mar 2015 16:49:47 -0400 Subject: [PATCH] Simplified temp filename generation. --- 3rdparty/libjasper/jas_stream.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/3rdparty/libjasper/jas_stream.c b/3rdparty/libjasper/jas_stream.c index 4c5db5871b..3ba7a837db 100644 --- a/3rdparty/libjasper/jas_stream.c +++ b/3rdparty/libjasper/jas_stream.c @@ -345,6 +345,7 @@ jas_stream_t *jas_stream_tmpfile() { jas_stream_t *stream; jas_stream_fileobj_t *obj; + char *tmpname; if (!(stream = jas_stream_create())) { return 0; @@ -365,14 +366,12 @@ jas_stream_t *jas_stream_tmpfile() #ifdef _WIN32 /* Choose a file name. */ - char lpTempPathBuffer[MAX_PATH]; - const DWORD dwRetVal = GetTempPath(MAX_PATH, lpTempPathBuffer); + tmpname = tempnam(NULL, NULL); + strcpy(obj->pathname, tmpname); + free(tmpname); /* Open the underlying file. */ - if (dwRetVal >= MAX_PATH || dwRetVal == 0 || - sprintf_s(obj->pathname, MAX_PATH, "%s\\tmp.XXXXXXXXXX", lpTempPathBuffer) <= 0 || - _mktemp_s(obj->pathname, MAX_PATH) || - (obj->fd = open(obj->pathname, O_CREAT | O_EXCL | O_RDWR | O_TRUNC | O_BINARY | O_TEMPORARY | _O_SHORT_LIVED, + if ((obj->fd = open(obj->pathname, O_CREAT | O_EXCL | O_RDWR | O_TRUNC | O_BINARY | O_TEMPORARY | _O_SHORT_LIVED, JAS_STREAM_PERMS)) < 0) { jas_stream_destroy(stream); return 0;