Commit 54ab3137 authored by Ashod Nakashian's avatar Ashod Nakashian

Simplified temp filename generation.

parent 6fd2fdc2
...@@ -345,6 +345,7 @@ jas_stream_t *jas_stream_tmpfile() ...@@ -345,6 +345,7 @@ jas_stream_t *jas_stream_tmpfile()
{ {
jas_stream_t *stream; jas_stream_t *stream;
jas_stream_fileobj_t *obj; jas_stream_fileobj_t *obj;
char *tmpname;
if (!(stream = jas_stream_create())) { if (!(stream = jas_stream_create())) {
return 0; return 0;
...@@ -365,14 +366,12 @@ jas_stream_t *jas_stream_tmpfile() ...@@ -365,14 +366,12 @@ jas_stream_t *jas_stream_tmpfile()
#ifdef _WIN32 #ifdef _WIN32
/* Choose a file name. */ /* Choose a file name. */
char lpTempPathBuffer[MAX_PATH]; tmpname = tempnam(NULL, NULL);
const DWORD dwRetVal = GetTempPath(MAX_PATH, lpTempPathBuffer); strcpy(obj->pathname, tmpname);
free(tmpname);
/* Open the underlying file. */ /* Open the underlying file. */
if (dwRetVal >= MAX_PATH || dwRetVal == 0 || if ((obj->fd = open(obj->pathname, O_CREAT | O_EXCL | O_RDWR | O_TRUNC | O_BINARY | O_TEMPORARY | _O_SHORT_LIVED,
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,
JAS_STREAM_PERMS)) < 0) { JAS_STREAM_PERMS)) < 0) {
jas_stream_destroy(stream); jas_stream_destroy(stream);
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment