diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2008-11-20 09:33:51 -0330 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2008-11-20 09:33:51 -0330 |
commit | 5744479ac651868774f90ccbcc2af59ca6800f00 (patch) | |
tree | 9e3a93dda6521118c74ac5f6719cc63b89a0020a /cpp/src/Slice/Preprocessor.cpp | |
parent | Removed debug statements (diff) | |
download | ice-5744479ac651868774f90ccbcc2af59ca6800f00.tar.bz2 ice-5744479ac651868774f90ccbcc2af59ca6800f00.tar.xz ice-5744479ac651868774f90ccbcc2af59ca6800f00.zip |
Bug 3550 - slice compiler not able to open tmp file on Vista
Diffstat (limited to 'cpp/src/Slice/Preprocessor.cpp')
-rw-r--r-- | cpp/src/Slice/Preprocessor.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
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; |