Earnie Boyd wrote:
> <quote who="Danny Smith">
>> That's correct, but there is a different problem with tmpfile. It puts
>> the file
>> in drive root directory, with obvious problems if that happens to be
>> read-only.
>>
>
> That's strange, according to MSDN it should open the tmpfile in the
> current working directory.
>
This is why I made that statement:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main (void)
{
char pathbuf[_MAX_PATH];
FILE* stream = tmpfile();
char* path
= _fullpath( pathbuf, stream->_tmpfname, _MAX_PATH);
printf( "Temporary file %s was created\n", path);
if (0xFFFFFFFF == GetFileAttributes(path))
printf ("File does not exist\n");
return 0;
}
When run from D:\develop\snippets
D:\develop\snippets>a
Temporary file D:\t5m was created
In any event, tmpfile() does create a real file and that causes problems with
read-only directories.
Danny
|