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()
{
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;
......
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