summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/BasicStream.cpp23
-rw-r--r--cpp/src/Ice/Instance.cpp51
2 files changed, 51 insertions, 23 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp
index 67cb13aa318..5267f96d7fe 100644
--- a/cpp/src/Ice/BasicStream.cpp
+++ b/cpp/src/Ice/BasicStream.cpp
@@ -733,6 +733,17 @@ IceInternal::BasicStream::read(vector<Byte>& v)
}
}
+template<class InputIterator, class OutputIterator>
+OutputIterator
+copyP(InputIterator first, InputIterator last, OutputIterator dest)
+{
+#if _WIN32 && _MSC_VER == 1400
+ return ::stdext::unchecked_copy(first, last, dest);
+#else
+ return ::std::copy(first, last, dest);
+#endif
+}
+
void
IceInternal::BasicStream::write(const vector<bool>& v)
{
@@ -742,7 +753,7 @@ IceInternal::BasicStream::write(const vector<bool>& v)
{
Container::size_type pos = b.size();
resize(pos + sz);
- copy(v.begin(), v.end(), b.begin() + pos);
+ copyP(v.begin(), v.end(), b.begin() + pos);
}
}
@@ -846,7 +857,7 @@ IceInternal::BasicStream::read(vector<Short>& v)
dest += 2 * sizeof(Short);
}
#else
- copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
+ copyP(begin, i, reinterpret_cast<Byte*>(&v[0]));
#endif
}
else
@@ -949,7 +960,7 @@ IceInternal::BasicStream::read(vector<Int>& v)
dest += 2 * sizeof(Int);
}
#else
- copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
+ copyP(begin, i, reinterpret_cast<Byte*>(&v[0]));
#endif
}
else
@@ -1076,7 +1087,7 @@ IceInternal::BasicStream::read(vector<Long>& v)
dest += 2 * sizeof(Long);
}
#else
- copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
+ copyP(begin, i, reinterpret_cast<Byte*>(&v[0]));
#endif
}
else
@@ -1179,7 +1190,7 @@ IceInternal::BasicStream::read(vector<Float>& v)
dest += 2 * sizeof(Float);
}
#else
- copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
+ copyP(begin, i, reinterpret_cast<Byte*>(&v[0]));
#endif
}
else
@@ -1306,7 +1317,7 @@ IceInternal::BasicStream::read(vector<Double>& v)
dest += 2 * sizeof(Double);
}
#else
- copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
+ copyP(begin, i, reinterpret_cast<Byte*>(&v[0]));
#endif
}
else
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index b7ee0a20fbf..2b1ce673e23 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -413,6 +413,34 @@ IceInternal::Instance::getDefaultContext() const
return _defaultContext;
}
+static FILE*
+freopenP(const char* path, const char* mode, FILE* stream)
+{
+ FILE* file;
+
+#if _WIN32 && _MSC_VER >= 1400
+ ::freopen_s(&file, path, mode, stream);
+ if(file == 0)
+ {
+ FileException ex(__FILE__, __LINE__);
+ ex.path = path;
+ char buf[1024];
+ ex.error = _strerror_s(buf, sizeof(buf), "freopen_s failed");
+ throw ex;
+ }
+#else
+ file = ::freopen(path, mode, stream);
+ if(file == 0)
+ {
+ FileException ex(__FILE__, __LINE__);
+ ex.path = path;
+ ex.error = getSystemErrno();
+ throw ex;
+ }
+#endif
+
+ return file;
+}
IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const PropertiesPtr& properties,
const LoggerPtr& logger) :
@@ -442,26 +470,15 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope
if(stdOutFilename != "")
{
- FILE* file = freopen(stdOutFilename.c_str(), "a", stdout);
- if(file == 0)
- {
- FileException ex(__FILE__, __LINE__);
- ex.path = stdOutFilename;
- ex.error = getSystemErrno();
- throw ex;
- }
+ FILE* file;
+#ifdef _WIN32
+ file = freopenP(stdOutFilename.c_str(), "a", stdout);
+#endif
}
if(stdErrFilename != "")
{
- FILE* file = freopen(stdErrFilename.c_str(), "a", stderr);
- if(file == 0)
- {
- FileException ex(__FILE__, __LINE__);
- ex.path = stdErrFilename;
- ex.error = getSystemErrno();
- throw ex;
- }
+ FILE* file = freopenP(stdErrFilename.c_str(), "a", stderr);
}
unsigned int seed = static_cast<unsigned int>(IceUtil::Time::now().toMicroSeconds());
@@ -895,6 +912,6 @@ IceInternal::Instance::destroy()
if(serverThreadPool)
{
serverThreadPool->joinWithAllThreads();
- }
+ }
return true;
}