Simplified temp filename generation.

This commit is contained in:
Ashod Nakashian 2015-03-29 16:49:47 -04:00
parent 6fd2fdc2e6
commit 54ab3137d5

View File

@ -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()
#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;