Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

GetTempFileName unexpected behavior

$
0
0

I have two tabs in the same IE process accessing a global file cache that uses the temp directory to store files. The file names are generated using GetTempFileName.

Below is the code simplified:


GetTempFileName(strTmpDir.c_str(), "as", 0, szFileName); //strTmpDir is a folder inside %TEMP% FILE* fp = NULL; errno_t err; err = fopen_s(&fp, szFileName, "wb"); if (( !fp ) || (0 != err)) { iErrLocation = 1; hr = E_FAIL; throw "Failed to open file"; } // Write bytes to the cache file if ( !fwrite(pBuf, nBytes, 1, fp) ) { iErrLocation = 2; hr = E_FAIL; throw "Failed to write to file"; } //at this point when the error occurs the file //could not be found int result = _stat(szFileName,&statBuf); if ( result != 0 ) { // switch (errno) { case ENOENT: strErrlocal = " File " + string(szFileName) + " not found.\n"; break; case EINVAL: strErrlocal = " Invalid parameter to _stat.\n"; break; default: /* Should never be reached. */ strErrlocal = " Unexpected error in _stat.\n";

break; } fclose(fp);


What could cause the file to be deleted in a multithreading scenario?

Thank you in advance.







Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>