From 5744479ac651868774f90ccbcc2af59ca6800f00 Mon Sep 17 00:00:00 2001 From: Dwayne Boone Date: Thu, 20 Nov 2008 09:33:51 -0330 Subject: Bug 3550 - slice compiler not able to open tmp file on Vista --- cpp/src/Slice/Preprocessor.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'cpp/src/Slice/Preprocessor.cpp') diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 1d331f24387..795adcb7e8b 100644 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -173,8 +173,35 @@ Slice::Preprocessor::preprocess(bool keepComments) // char* buf = mcpp_get_mem_buffer(Out); + // + // First try to open temporay file in tmp directory. + // +#ifdef _WIN32 + TCHAR buffer[512]; + DWORD ret = GetTempPath(512, buffer); + if(ret != 0 && ret < 512) + { + _cppFile = string(buffer) + "\\.preprocess." + IceUtil::generateUUID(); + _cppHandle = ::_wfopen(IceUtil::stringToWstring(_cppFile).c_str(), IceUtil::stringToWstring("w+").c_str()); + } +#else _cppHandle = tmpfile(); - if(_cppHandle != NULL) +#endif + + // + // If that fails try to open file in current directory. + // + if(_cppHandle == 0) + { + _cppFile = ".preprocess." + IceUtil::generateUUID(); +#ifdef _WIN32 + _cppHandle = ::_wfopen(IceUtil::stringToWstring(_cppFile).c_str(), IceUtil::stringToWstring("w+").c_str()); +#else + _cppHandle = ::fopen(_cppFile.c_str(), "w+"); +#endif + } + + if(_cppHandle != 0) { if(buf) { @@ -184,7 +211,7 @@ Slice::Preprocessor::preprocess(bool keepComments) } else { - fprintf(stderr, "Could not open temporary file.\n"); + cerr << "Could not open temporary file: " << _cppFile << endl; } } @@ -460,6 +487,15 @@ Slice::Preprocessor::close() int status = fclose(_cppHandle); _cppHandle = 0; + if(_cppFile != "") + { +#ifdef _WIN32 + _unlink(_cppFile.c_str()); +#else + unlink(_cppFile.c_str()); +#endif + } + if(status != 0) { return false; -- cgit v1.2.3