This function fails to work on my Win7 RC currently. The tmpfile() function attempts to create a file in the root (C:\), which is has no permission for. This was, admittedly, after a machine crash. I'm trying to open up my directory, but I'm not sure why the root is suddenly closed down. Also, I find the root directory of a drive a funny location for a temporary file, but that may be just me.
(one day later)
I managed to fix it by creating my own tmpfile() function to replace the faulty default one (running Win7/build7100, Visual C++ 2008SP1):
FILE *myTmpFile()
// Creates a temp file in a more readable location than tmpfile() on Win32
// (which writes in root, not allowed in Vista/Win7)
{
char buf[1024],buf2[1024],bufN[256];
int n;
FILE *fp;
GetTempPath(1024,buf);
for(n=_getpid();;n++)
{
strcpy_s(buf2,sizeof(buf2),buf);
sprintf_s(bufN,sizeof(bufN),"jpeg_rvg_%d",n);
strcat_s(buf2,sizeof(buf2),bufN);
fp=0;
// Exists?
fp=fopen(buf2,"rb");
if(fp)
{
fclose(fp);
continue;
}
// Clear file and allow reads
fopen_s(&fp,buf2,"wb+");
if(fp)return fp;
}
// We'll never get here
return 0;
}
Not sure if tmpfile() would create auto-deleting files, but this function just creates (but never deletes) the temp file.