Having looked at it a bit more, I wouldn't bother
jas_image_decode does that for you when you pass -1 in as the fmt, so I don't think it's relevant.
What is relevant is your original response - this seems to be a problem with JasPer, specifically, jas_stream_tmpfile(). It seems to create a temp file like this:
_snprintf(obj->pathname, L_tmpnam, "%stmp.XXXXXXXXXX", P_tmpdir);
and then open it with O_EXCL.
But that code is called in a loop in jas_image_create() , through jas_image_cmpt_create()
Code: Select all
/* Create the individual image components. */
for (cmptno = 0, cmptparm = cmptparms; cmptno < numcmpts; ++cmptno,
++cmptparm) {
if (!(image->cmpts_[cmptno] = jas_image_cmpt_create(cmptparm->tlx,
cmptparm->tly, cmptparm->hstep, cmptparm->vstep,
cmptparm->width, cmptparm->height, cmptparm->prec,
cmptparm->sgnd, inmem))) {
jas_image_destroy(image);
return 0;
}
++image->numcmpts_;
}
and there is this comment in jas_stream_tmpfile() which probably explains what's going on:
Code: Select all
/* Unlink the file so that it will disappear if the program
terminates abnormally. */
/* Under UNIX, one can unlink an open file and continue to do I/O
on it. Not all operating systems support this functionality, however.
For example, under Microsoft Windows the unlink operation will fail,
since the file is open. */
if (unlink(obj->pathname)) {
/* We will try unlinking the file again after it is closed. */
obj->flags |= JAS_STREAM_FILEOBJ_DELONCLOSE;
}
However, looking at it in a bit more depth, the snprintf() call is implemented a bit weirdly on windows
http://msdn.microsoft.com/en-us/library ... 10%29.aspx
Let len be the length of the formatted data string (not including the terminating null). len and count are in bytes for _snprintf, wide characters for _snwprintf.
If len < count, then len characters are stored in buffer, a null-terminator is appended, and len is returned.
If len = count, then len characters are stored in buffer, no null-terminator is appended, and len is returned.
If len > count, then count characters are stored in buffer, no null-terminator is appended, and a negative value is returned.
So, on my windows box, L_tmpnam is 14. obj.pathname is L_tmpnam + 1, so 15. So you end up with a non null terminated path name.
Sticking the null terminator on at least gets me to the point where the unlink fails due to "dos error 32" or "sharing violation", which is what that comment seems to suggest. But if that's the case, I can't see how this is meant to work on windows