summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/Preprocessor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Slice/Preprocessor.cpp')
-rw-r--r--cpp/src/Slice/Preprocessor.cpp67
1 files changed, 45 insertions, 22 deletions
diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp
index ac62657e59a..70eb7147894 100644
--- a/cpp/src/Slice/Preprocessor.cpp
+++ b/cpp/src/Slice/Preprocessor.cpp
@@ -10,7 +10,6 @@
#include <IceUtil/DisableWarnings.h>
#include <Slice/Preprocessor.h>
#include <Slice/Util.h>
-#include <Slice/SignalHandler.h>
#include <IceUtil/StringUtil.h>
#include <IceUtil/FileUtil.h>
#include <IceUtil/UUID.h>
@@ -29,20 +28,6 @@ using namespace std;
using namespace Slice;
//
-// Callback for Crtl-C signal handling
-//
-static Preprocessor* _preprocess = 0;
-
-static void closeCallback()
-{
- if(_preprocess != 0)
- {
- _preprocess->close();
- }
-}
-
-
-//
// mcpp defines
//
namespace Slice
@@ -65,8 +50,6 @@ Slice::Preprocessor::Preprocessor(const string& path, const string& fileName, co
_args(args),
_cppHandle(0)
{
- _preprocess = this;
- SignalHandler::setCallback(closeCallback);
}
Slice::Preprocessor::~Preprocessor()
@@ -174,8 +157,36 @@ Slice::Preprocessor::preprocess(bool keepComments)
//
char* buf = mcpp_get_mem_buffer(Out);
+ //
+ // First try to open temporay file in tmp directory.
+ //
+#ifdef _WIN32
+ wchar_t* name = _wtempnam(NULL, L".preprocess");
+ if(name)
+ {
+ _cppFile = wstring(name);
+ free(name);
+ _cppHandle = ::_wfopen(_cppFile.c_str(), L"w+");
+ }
+#else
_cppHandle = tmpfile();
- if(_cppHandle != NULL)
+#endif
+
+ //
+ // If that fails try to open file in current directory.
+ //
+ if(_cppHandle == 0)
+ {
+#ifdef _WIN32
+ _cppFile = L".preprocess." + IceUtil::stringToWstring(IceUtil::generateUUID());
+ _cppHandle = ::_wfopen(_cppFile.c_str(), L"w+");
+#else
+ _cppFile = ".preprocess." + IceUtil::generateUUID();
+ _cppHandle = ::fopen(_cppFile.c_str(), "w+");
+#endif
+ }
+
+ if(_cppHandle != 0)
{
if(buf)
{
@@ -185,7 +196,13 @@ Slice::Preprocessor::preprocess(bool keepComments)
}
else
{
- fprintf(stderr, "Could not open temporary file.\n");
+ cerr << "Could not open temporary file: ";
+#ifdef _WIN32
+ cerr << IceUtil::wstringToString(_cppFile);
+#else
+ cerr << _cppFile;
+#endif
+ cerr << endl;
}
}
@@ -453,14 +470,20 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin
bool
Slice::Preprocessor::close()
{
- _preprocess = 0;
- SignalHandler::setCallback(0);
-
if(_cppHandle != 0)
{
int status = fclose(_cppHandle);
_cppHandle = 0;
+ if(_cppFile.size() != 0)
+ {
+#ifdef _WIN32
+ _wunlink(_cppFile.c_str());
+#else
+ unlink(_cppFile.c_str());
+#endif
+ }
+
if(status != 0)
{
return false;