summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2008-01-23 11:31:53 +0100
committerBenoit Foucher <benoit@zeroc.com>2008-01-23 11:31:53 +0100
commitc7fb26230801e62f3e690a8948d37c33517c4c13 (patch)
treef17689f60e13fbbd20d12473272a6f0652f39a78 /cpp
parentremoving EventHandler in C# (diff)
downloadice-c7fb26230801e62f3e690a8948d37c33517c4c13.tar.bz2
ice-c7fb26230801e62f3e690a8948d37c33517c4c13.tar.xz
ice-c7fb26230801e62f3e690a8948d37c33517c4c13.zip
- Added IceUtil::SyscallException and cleaned up few IceUtil exceptions
- Added errorToString() and lastErrorToString() functions to IceUtil/StringUtil.h - Replaced multiple implementations of errorToString methods with the IceUtil one. - Fixed bug 2641.
Diffstat (limited to 'cpp')
-rw-r--r--cpp/include/IceUtil/Exception.h22
-rw-r--r--cpp/include/IceUtil/Random.h18
-rw-r--r--cpp/include/IceUtil/StringUtil.h9
-rw-r--r--cpp/include/IceUtil/ThreadException.h5
-rw-r--r--cpp/include/IceUtil/Time.h3
-rwxr-xr-xcpp/src/Ice/EventLoggerI.cpp10
-rw-r--r--cpp/src/Ice/Exception.cpp12
-rw-r--r--cpp/src/Ice/Network.cpp219
-rw-r--r--cpp/src/Ice/Network.h2
-rw-r--r--cpp/src/Ice/Selector.cpp9
-rwxr-xr-xcpp/src/Ice/Service.cpp29
-rwxr-xr-xcpp/src/Ice/StringConverter.cpp42
-rw-r--r--cpp/src/Ice/UdpTransceiver.cpp2
-rw-r--r--cpp/src/IceGrid/PlatformInfo.cpp36
-rw-r--r--cpp/src/IceGrid/ServerI.cpp12
-rw-r--r--cpp/src/IcePatch2/Calc.cpp3
-rwxr-xr-xcpp/src/IcePatch2/ClientUtil.cpp17
-rw-r--r--cpp/src/IcePatch2/Server.cpp3
-rw-r--r--cpp/src/IcePatch2/Util.cpp129
-rw-r--r--cpp/src/IceUtil/Exception.cpp61
-rw-r--r--cpp/src/IceUtil/Random.cpp76
-rw-r--r--cpp/src/IceUtil/StringUtil.cpp224
-rw-r--r--cpp/src/IceUtil/ThreadException.cpp46
-rw-r--r--cpp/src/IceUtil/Time.cpp91
-rwxr-xr-xcpp/src/iceserviceinstall/ServiceInstaller.cpp85
-rwxr-xr-xcpp/src/iceserviceinstall/ServiceInstaller.h1
-rw-r--r--cpp/src/slice2html/Main.cpp4
27 files changed, 510 insertions, 660 deletions
diff --git a/cpp/include/IceUtil/Exception.h b/cpp/include/IceUtil/Exception.h
index 02b0b72d93f..1fb9b68de9f 100644
--- a/cpp/include/IceUtil/Exception.h
+++ b/cpp/include/IceUtil/Exception.h
@@ -65,17 +65,35 @@ public:
IllegalArgumentException(const char*, int, const std::string&);
virtual ~IllegalArgumentException() throw();
virtual std::string ice_name() const;
+ virtual void ice_print(std::ostream&) const;
virtual Exception* ice_clone() const;
virtual void ice_throw() const;
- std::string reason;
+ std::string reason() const;
private:
static const char* _name;
+ std::string _reason;
};
-ICE_UTIL_API std::ostream& operator<<(std::ostream&, const IllegalArgumentException&);
+class ICE_UTIL_API SyscallException : public Exception
+{
+public:
+
+ SyscallException(const char*, int, int);
+ virtual std::string ice_name() const;
+ virtual void ice_print(std::ostream&) const;
+ virtual Exception* ice_clone() const;
+ virtual void ice_throw() const;
+
+ int error() const;
+
+private:
+
+ const int _error;
+ static const char* _name;
+};
}
diff --git a/cpp/include/IceUtil/Random.h b/cpp/include/IceUtil/Random.h
index 021b13bd1ea..50665df42d7 100644
--- a/cpp/include/IceUtil/Random.h
+++ b/cpp/include/IceUtil/Random.h
@@ -16,24 +16,6 @@
namespace IceUtilInternal
{
-class ICE_UTIL_API RandomGeneratorException : public IceUtil::Exception
-{
-public:
-
- RandomGeneratorException(const char*, int, int = 0);
- virtual std::string ice_name() const;
- virtual void ice_print(std::ostream&) const;
- virtual IceUtil::Exception* ice_clone() const;
- virtual void ice_throw() const;
-
- int error() const;
-
-private:
-
- const int _error;
- static const char* _name;
-};
-
ICE_UTIL_API void generateRandom(char*, int);
ICE_UTIL_API int random(int = 0);
diff --git a/cpp/include/IceUtil/StringUtil.h b/cpp/include/IceUtil/StringUtil.h
index 1073bfc2573..d868d1e1fe3 100644
--- a/cpp/include/IceUtil/StringUtil.h
+++ b/cpp/include/IceUtil/StringUtil.h
@@ -51,6 +51,15 @@ ICE_UTIL_API std::string::size_type checkQuote(const std::string&, std::string::
//
ICE_UTIL_API bool match(const std::string&, const std::string&, bool = false);
+//
+// Get the error message for the last error code or given error code.
+//
+ICE_UTIL_API std::string lastErrorToString();
+#ifdef _WIN32
+ICE_UTIL_API std::string errorToString(int, LPCVOID = NULL);
+#else
+ICE_UTIL_API std::string errorToString(int);
+#endif
}
#endif
diff --git a/cpp/include/IceUtil/ThreadException.h b/cpp/include/IceUtil/ThreadException.h
index cf6c6289c9a..010a6ccad5c 100644
--- a/cpp/include/IceUtil/ThreadException.h
+++ b/cpp/include/IceUtil/ThreadException.h
@@ -16,20 +16,17 @@
namespace IceUtil
{
-class ICE_UTIL_API ThreadSyscallException : public Exception
+class ICE_UTIL_API ThreadSyscallException : public SyscallException
{
public:
ThreadSyscallException(const char*, int, int);
virtual std::string ice_name() const;
- virtual void ice_print(std::ostream&) const;
virtual Exception* ice_clone() const;
virtual void ice_throw() const;
- int error() const;
private:
- const int _error;
static const char* _name;
};
diff --git a/cpp/include/IceUtil/Time.h b/cpp/include/IceUtil/Time.h
index 60e87501031..a723bb04bcb 100644
--- a/cpp/include/IceUtil/Time.h
+++ b/cpp/include/IceUtil/Time.h
@@ -195,9 +195,6 @@ private:
Time(Int64);
Int64 _usec;
-#ifdef _WIN32
- static Int64 _frequency;
-#endif
};
ICE_UTIL_API std::ostream& operator<<(std::ostream&, const Time&);
diff --git a/cpp/src/Ice/EventLoggerI.cpp b/cpp/src/Ice/EventLoggerI.cpp
index b52e6981624..72f4397f481 100755
--- a/cpp/src/Ice/EventLoggerI.cpp
+++ b/cpp/src/Ice/EventLoggerI.cpp
@@ -7,10 +7,10 @@
//
// **********************************************************************
+#include <IceUtil/StringUtil.h>
#include <Ice/EventLoggerI.h>
#include <Ice/EventLoggerMsg.h>
#include <Ice/LocalException.h>
-#include <Ice/Network.h> // For errorToString
#include <IceUtil/StaticMutex.h>
using namespace std;
@@ -122,7 +122,7 @@ Ice::EventLoggerI::print(const string& message)
if(!ReportEvent(_source, EVENTLOG_INFORMATION_TYPE, 0, EVENT_LOGGER_MSG, 0, 1, 0, str, 0))
{
IceUtil::StaticMutex::Lock sync(outputMutex);
- cerr << "ReportEvent failed `" << IceInternal::errorToString(GetLastError()) << "':\n" << message << endl;
+ cerr << "ReportEvent failed `" << IceUtilInternal::errorToString(GetLastError()) << "':\n" << message << endl;
}
}
@@ -142,7 +142,7 @@ Ice::EventLoggerI::trace(const string& category, const string& message)
if(!ReportEvent(_source, EVENTLOG_INFORMATION_TYPE, 0, EVENT_LOGGER_MSG, 0, 1, 0, str, 0))
{
IceUtil::StaticMutex::Lock sync(outputMutex);
- cerr << "ReportEvent failed `" << IceInternal::errorToString(GetLastError()) << "':\n" << message << endl;
+ cerr << "ReportEvent failed `" << IceUtilInternal::errorToString(GetLastError()) << "':\n" << message << endl;
}
}
@@ -154,7 +154,7 @@ Ice::EventLoggerI::warning(const string& message)
if(!ReportEvent(_source, EVENTLOG_WARNING_TYPE, 0, EVENT_LOGGER_MSG, 0, 1, 0, str, 0))
{
IceUtil::StaticMutex::Lock sync(outputMutex);
- cerr << "ReportEvent failed `" << IceInternal::errorToString(GetLastError()) << "':\n" << message << endl;
+ cerr << "ReportEvent failed `" << IceUtilInternal::errorToString(GetLastError()) << "':\n" << message << endl;
}
}
@@ -166,7 +166,7 @@ Ice::EventLoggerI::error(const string& message)
if(!ReportEvent(_source, EVENTLOG_ERROR_TYPE, 0, EVENT_LOGGER_MSG, 0, 1, 0, str, 0))
{
IceUtil::StaticMutex::Lock sync(outputMutex);
- cerr << "ReportEvent failed `" << IceInternal::errorToString(GetLastError()) << "':\n" << message << endl;
+ cerr << "ReportEvent failed `" << IceUtilInternal::errorToString(GetLastError()) << "':\n" << message << endl;
}
}
diff --git a/cpp/src/Ice/Exception.cpp b/cpp/src/Ice/Exception.cpp
index 7b7a87f746c..651c9f7277d 100644
--- a/cpp/src/Ice/Exception.cpp
+++ b/cpp/src/Ice/Exception.cpp
@@ -262,7 +262,7 @@ Ice::SyscallException::ice_print(ostream& out) const
Exception::ice_print(out);
if(error != 0)
{
- out << ":\nsyscall exception: " << errorToString(error);
+ out << ":\nsyscall exception: " << IceUtilInternal::errorToString(error);
}
}
@@ -277,7 +277,7 @@ Ice::SocketException::ice_print(ostream& out) const
}
else
{
- out << errorToString(error);
+ out << IceUtilInternal::errorToString(error);
}
}
@@ -292,7 +292,7 @@ Ice::FileException::ice_print(ostream& out) const
}
else
{
- out << errorToString(error);
+ out << IceUtilInternal::errorToString(error);
}
if(!path.empty())
{
@@ -304,14 +304,14 @@ void
Ice::ConnectFailedException::ice_print(ostream& out) const
{
Exception::ice_print(out);
- out << ":\nconnect failed: " << errorToString(error);
+ out << ":\nconnect failed: " << IceUtilInternal::errorToString(error);
}
void
Ice::ConnectionRefusedException::ice_print(ostream& out) const
{
Exception::ice_print(out);
- out << ":\nconnection refused: " << errorToString(error);
+ out << ":\nconnection refused: " << IceUtilInternal::errorToString(error);
}
void
@@ -325,7 +325,7 @@ Ice::ConnectionLostException::ice_print(ostream& out) const
}
else
{
- out << errorToString(error);
+ out << IceUtilInternal::errorToString(error);
}
}
diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp
index 02b2ce85fba..3af3dea5438 100644
--- a/cpp/src/Ice/Network.cpp
+++ b/cpp/src/Ice/Network.cpp
@@ -17,7 +17,7 @@
#include <netinet/in.h>
#endif
-#include <IceUtil/StaticMutex.h>
+#include <IceUtil/StringUtil.h>
#include <Ice/Network.h>
#include <Ice/LocalException.h>
#include <Ice/Properties.h> // For setTcpBufSize
@@ -1538,219 +1538,14 @@ IceInternal::createPipe(SOCKET fds[2])
#ifdef _WIN32
string
-IceInternal::errorToString(int error)
-{
- if(error < WSABASEERR)
- {
- LPVOID lpMsgBuf = 0;
- DWORD ok = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- error,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR)&lpMsgBuf,
- 0,
- NULL);
- if(ok)
- {
- LPCTSTR msg = (LPCTSTR)lpMsgBuf;
- assert(msg && strlen((const char*)msg) > 0);
- string result = (const char*)msg;
- if(result[result.length() - 1] == '\n')
- {
- result = result.substr(0, result.length() - 2);
- }
- LocalFree(lpMsgBuf);
- return result;
- }
- else
- {
- ostringstream os;
- os << "unknown error: " << error;
- return os.str();
- }
- }
-
- switch(error)
- {
- case WSAEINTR:
- return "WSAEINTR";
-
- case WSAEBADF:
- return "WSAEBADF";
-
- case WSAEACCES:
- return "WSAEACCES";
-
- case WSAEFAULT:
- return "WSAEFAULT";
-
- case WSAEINVAL:
- return "WSAEINVAL";
-
- case WSAEMFILE:
- return "WSAEMFILE";
-
- case WSAEWOULDBLOCK:
- return "WSAEWOULDBLOCK";
-
- case WSAEINPROGRESS:
- return "WSAEINPROGRESS";
-
- case WSAEALREADY:
- return "WSAEALREADY";
-
- case WSAENOTSOCK:
- return "WSAENOTSOCK";
-
- case WSAEDESTADDRREQ:
- return "WSAEDESTADDRREQ";
-
- case WSAEMSGSIZE:
- return "WSAEMSGSIZE";
-
- case WSAEPROTOTYPE:
- return "WSAEPROTOTYPE";
-
- case WSAENOPROTOOPT:
- return "WSAENOPROTOOPT";
-
- case WSAEPROTONOSUPPORT:
- return "WSAEPROTONOSUPPORT";
-
- case WSAESOCKTNOSUPPORT:
- return "WSAESOCKTNOSUPPORT";
-
- case WSAEOPNOTSUPP:
- return "WSAEOPNOTSUPP";
-
- case WSAEPFNOSUPPORT:
- return "WSAEPFNOSUPPORT";
-
- case WSAEAFNOSUPPORT:
- return "WSAEAFNOSUPPORT";
-
- case WSAEADDRINUSE:
- return "WSAEADDRINUSE";
-
- case WSAEADDRNOTAVAIL:
- return "WSAEADDRNOTAVAIL";
-
- case WSAENETDOWN:
- return "WSAENETDOWN";
-
- case WSAENETUNREACH:
- return "WSAENETUNREACH";
-
- case WSAENETRESET:
- return "WSAENETRESET";
-
- case WSAECONNABORTED:
- return "WSAECONNABORTED";
-
- case WSAECONNRESET:
- return "WSAECONNRESET";
-
- case WSAENOBUFS:
- return "WSAENOBUFS";
-
- case WSAEISCONN:
- return "WSAEISCONN";
-
- case WSAENOTCONN:
- return "WSAENOTCONN";
-
- case WSAESHUTDOWN:
- return "WSAESHUTDOWN";
-
- case WSAETOOMANYREFS:
- return "WSAETOOMANYREFS";
-
- case WSAETIMEDOUT:
- return "WSAETIMEDOUT";
-
- case WSAECONNREFUSED:
- return "WSAECONNREFUSED";
-
- case WSAELOOP:
- return "WSAELOOP";
-
- case WSAENAMETOOLONG:
- return "WSAENAMETOOLONG";
-
- case WSAEHOSTDOWN:
- return "WSAEHOSTDOWN";
-
- case WSAEHOSTUNREACH:
- return "WSAEHOSTUNREACH";
-
- case WSAENOTEMPTY:
- return "WSAENOTEMPTY";
-
- case WSAEPROCLIM:
- return "WSAEPROCLIM";
-
- case WSAEUSERS:
- return "WSAEUSERS";
-
- case WSAEDQUOT:
- return "WSAEDQUOT";
-
- case WSAESTALE:
- return "WSAESTALE";
-
- case WSAEREMOTE:
- return "WSAEREMOTE";
-
- case WSAEDISCON:
- return "WSAEDISCON";
-
- case WSASYSNOTREADY:
- return "WSASYSNOTREADY";
-
- case WSAVERNOTSUPPORTED:
- return "WSAVERNOTSUPPORTED";
-
- case WSANOTINITIALISED:
- return "WSANOTINITIALISED";
-
- case WSAHOST_NOT_FOUND:
- return "WSAHOST_NOT_FOUND";
-
- case WSATRY_AGAIN:
- return "WSATRY_AGAIN";
-
- case WSANO_RECOVERY:
- return "WSANO_RECOVERY";
-
- case WSANO_DATA:
- return "WSANO_DATA";
-
- default:
- {
- ostringstream os;
- os << "unknown socket error: " << error;
- return os.str();
- }
- }
-}
-
-string
IceInternal::errorToStringDNS(int error)
{
- return errorToString(error);
+ return IceUtilInternal::errorToString(error);
}
#else
string
-IceInternal::errorToString(int error)
-{
- return strerror(error);
-}
-
-string
IceInternal::errorToStringDNS(int error)
{
return gai_strerror(error);
@@ -1758,16 +1553,6 @@ IceInternal::errorToStringDNS(int error)
#endif
-string
-IceInternal::lastErrorToString()
-{
-#ifdef _WIN32
- return errorToString(WSAGetLastError());
-#else
- return errorToString(errno);
-#endif
-}
-
std::string
IceInternal::fdToString(SOCKET fd)
{
diff --git a/cpp/src/Ice/Network.h b/cpp/src/Ice/Network.h
index ed09190e27b..57b792d8794 100644
--- a/cpp/src/Ice/Network.h
+++ b/cpp/src/Ice/Network.h
@@ -111,9 +111,7 @@ ICE_API int compareAddress(const struct sockaddr_storage&, const struct sockaddr
ICE_API void createPipe(SOCKET fds[2]);
-ICE_API std::string errorToString(int);
ICE_API std::string errorToStringDNS(int);
-ICE_API std::string lastErrorToString();
ICE_API std::string fdToString(SOCKET);
ICE_API std::string addressesToString(const struct sockaddr_storage&, const struct sockaddr_storage&, bool);
diff --git a/cpp/src/Ice/Selector.cpp b/cpp/src/Ice/Selector.cpp
index 5e82c2f7ee3..822a5bedd48 100644
--- a/cpp/src/Ice/Selector.cpp
+++ b/cpp/src/Ice/Selector.cpp
@@ -8,6 +8,7 @@
// **********************************************************************
#include <IceUtil/DisableWarnings.h>
+#include <IceUtil/StringUtil.h>
#include <Ice/Selector.h>
#include <Ice/Network.h>
#include <Ice/Instance.h>
@@ -146,7 +147,7 @@ IceInternal::Selector::add(SOCKET fd, SocketStatus status)
{
Error out(_instance->initializationData().logger);
out << "error while adding filedescriptor to epoll set:\n";
- out << errorToString(getSocketErrno());
+ out << IceInternalUtil::errorToString(getSocketErrno());
}
_events.resize(_events.size() + 1);
#elif defined(__APPLE__)
@@ -167,7 +168,7 @@ IceInternal::Selector::add(SOCKET fd, SocketStatus status)
{
Error out(_instance->initializationData().logger);
out << "error while adding filedescriptor to kqueue:\n";
- out << errorToString(getSocketErrno());
+ out << IceUtilInternal::errorToString(getSocketErrno());
}
_events.resize(_events.size() + 1);
#else
@@ -219,7 +220,7 @@ Selector::remove(SOCKET fd, SocketStatus status)
//
// Error out(_instance->initializationData().logger);
// out << "error while removing filedescriptor from epoll set:\n";
-// out << errorToString(getSocketErrno());
+// out << IceUtilInternal::errorToString(getSocketErrno());
}
_events.resize(_events.size() - 1);
#elif defined(__APPLE__)
@@ -244,7 +245,7 @@ Selector::remove(SOCKET fd, SocketStatus status)
//
// Error out(_instance->initializationData().logger);
// out << "error while removing filedescriptor from kqueue:\n";
-// out << errorToString(getSocketErrno());
+// out << IceUtilInternal::errorToString(getSocketErrno());
}
_events.resize(_events.size() - 1);
#else
diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp
index ed6b2c98a1d..edc357c4620 100755
--- a/cpp/src/Ice/Service.cpp
+++ b/cpp/src/Ice/Service.cpp
@@ -9,6 +9,7 @@
#include <IceUtil/DisableWarnings.h>
#include <IceUtil/CtrlCHandler.h>
+#include <IceUtil/StringUtil.h>
#include <IceUtil/Thread.h>
#include <IceUtil/Monitor.h>
#include <IceUtil/Mutex.h>
@@ -1193,33 +1194,7 @@ Ice::Service::initializeCommunicator(int& argc, char* argv[], const Initializati
void
Ice::Service::syserror(const string& msg)
{
- string errmsg;
-#ifdef _WIN32
- int err = GetLastError();
- if(err < WSABASEERR)
- {
- LPVOID lpMsgBuf = 0;
- DWORD ok = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- 0,
- err,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR)&lpMsgBuf,
- 0,
- 0);
- if(ok)
- {
- LPCTSTR str = (LPCTSTR)lpMsgBuf;
- assert(str && strlen((const char*)str) > 0);
- errmsg = (const char*)str;
- LocalFree(lpMsgBuf);
- }
- }
-#else
- int err = errno;
- errmsg = strerror(err);
-#endif
+ string errmsg = IceUtilInternal::lastErrorToString();
if(_logger)
{
ostringstream ostr;
diff --git a/cpp/src/Ice/StringConverter.cpp b/cpp/src/Ice/StringConverter.cpp
index ec88ab47188..a89fa716494 100755
--- a/cpp/src/Ice/StringConverter.cpp
+++ b/cpp/src/Ice/StringConverter.cpp
@@ -9,6 +9,7 @@
#include <Ice/StringConverter.h>
#include <IceUtil/IceUtil.h>
+#include <IceUtil/StringUtil.h>
#include <IceUtil/ScopedArray.h>
#include <Ice/LocalException.h>
@@ -16,43 +17,6 @@ using namespace IceUtil;
using namespace IceUtilInternal;
using namespace std;
-
-#ifdef _WIN32
-namespace
-{
-//
-// Helper function
-//
-
-string getMessageForLastError()
-{
- LPVOID lpMsgBuf = 0;
- DWORD ok = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR)&lpMsgBuf,
- 0,
- NULL);
-
- string msg;
- if(ok)
- {
- msg = (LPCTSTR)lpMsgBuf;
- LocalFree(lpMsgBuf);
- }
- else
- {
- msg = "Unknown Windows error";
- }
- return msg;
-}
-}
-#endif
-
-
namespace Ice
{
@@ -162,7 +126,7 @@ WindowsStringConverter::toUTF8(const char* sourceStart,
if(writtenWchar == 0)
{
- throw StringConversionException(__FILE__, __LINE__, getMessageForLastError());
+ throw StringConversionException(__FILE__, __LINE__, IceUtilInternal::lastErrorToString());
}
//
@@ -203,7 +167,7 @@ WindowsStringConverter::fromUTF8(const Byte* sourceStart, const Byte* sourceEnd,
if(writtenChar == 0)
{
- throw StringConversionException(__FILE__, __LINE__, getMessageForLastError());
+ throw StringConversionException(__FILE__, __LINE__, IceUtilInternal::lastErrorToString());
}
target.assign(buffer.get(), writtenChar);
diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp
index 96d17fc3bcb..fa58c144866 100644
--- a/cpp/src/Ice/UdpTransceiver.cpp
+++ b/cpp/src/Ice/UdpTransceiver.cpp
@@ -511,13 +511,13 @@ IceInternal::UdpTransceiver::UdpTransceiver(const InstancePtr& instance, const s
if(multicast)
{
setReuseAddress(_fd, true);
- struct sockaddr_storage addr;
//
// Windows does not allow binding to the mcast address itself
// so we bind to INADDR_ANY (0.0.0.0) instead.
//
#ifdef _WIN32
+ struct sockaddr_storage addr;
getAddressForServer("", port, addr, instance->protocolSupport());
doBind(_fd, addr);
#else
diff --git a/cpp/src/IceGrid/PlatformInfo.cpp b/cpp/src/IceGrid/PlatformInfo.cpp
index 462e0d70c1d..52838371502 100644
--- a/cpp/src/IceGrid/PlatformInfo.cpp
+++ b/cpp/src/IceGrid/PlatformInfo.cpp
@@ -7,11 +7,11 @@
//
// **********************************************************************
+#include <IceUtil/StringUtil.h>
#include <Ice/Communicator.h>
#include <Ice/Properties.h>
#include <Ice/LocalException.h>
#include <Ice/LoggerUtil.h>
-#include <Ice/ProtocolPluginFacade.h> // Just to get the hostname
#include <IceGrid/PlatformInfo.h>
#include <IceGrid/TraceLevels.h>
@@ -46,37 +46,7 @@ namespace
string
pdhErrorToString(PDH_STATUS err)
{
- LPVOID lpMsgBuf = 0;
-
- DWORD ok = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_HMODULE |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- GetModuleHandle(TEXT("PDH.DLL")),
- err,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR)&lpMsgBuf,
- 0,
- NULL);
-
- string message;
- if(ok)
- {
- LPCTSTR msg = (LPCTSTR)lpMsgBuf;
- assert(msg && strlen(static_cast<const char*>(msg)) > 0);
- message = static_cast<const char*>(msg);
- if(message[message.length() - 1] == '\n')
- {
- message = message.substr(0, message.length() - 2);
- }
- LocalFree(lpMsgBuf);
- }
- else
- {
- ostringstream os;
- os << "unknown error: " << err;
- message = os.str();
- }
- return message;
+ return IceUtilInternal::errorToString(err, GetModuleHandle(TEXT("PDH.DLL")));
}
static string
@@ -302,7 +272,7 @@ PlatformInfo::PlatformInfo(const string& prefix,
if(getcwd(cwd, PATH_MAX) == NULL)
#endif
{
- throw "cannot get the current directory:\n" + IcePatch2::lastError();
+ throw "cannot get the current directory:\n" + IceUtilInternal::lastErrorToString();
}
_cwd = string(cwd);
diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp
index d4eacad1224..fd0c8065c2a 100644
--- a/cpp/src/IceGrid/ServerI.cpp
+++ b/cpp/src/IceGrid/ServerI.cpp
@@ -49,7 +49,7 @@ chownRecursive(const string& path, uid_t uid, gid_t gid)
DIR* d;
if((d = opendir(path.c_str())) == 0)
{
- throw "cannot read directory `" + path + "':\n" + IcePatch2::lastError();
+ throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
struct dirent* entry;
@@ -60,7 +60,7 @@ chownRecursive(const string& path, uid_t uid, gid_t gid)
if(namelist == 0)
{
closedir(d);
- throw "cannot read directory `" + path + "':\n" + IcePatch2::lastError();
+ throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
size_t entrysize = sizeof(struct dirent) - sizeof(entry->d_name) + strlen(entry->d_name) + 1;
@@ -68,7 +68,7 @@ chownRecursive(const string& path, uid_t uid, gid_t gid)
if(namelist[n] == 0)
{
closedir(d);
- throw "cannot read directory `" + path + "':\n" + IcePatch2::lastError();
+ throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
memcpy(namelist[n], entry, entrysize);
++n;
@@ -76,7 +76,7 @@ chownRecursive(const string& path, uid_t uid, gid_t gid)
if(closedir(d))
{
- throw "cannot read directory `" + path + "':\n" + IcePatch2::lastError();
+ throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
for(int i = 0; i < n; ++i)
@@ -90,13 +90,13 @@ chownRecursive(const string& path, uid_t uid, gid_t gid)
name = path + "/" + name;
if(chown(name.c_str(), uid, gid) != 0)
{
- throw "can't change permissions on `" + name + "':\n" + IcePatch2::lastError();
+ throw "can't change permissions on `" + name + "':\n" + IceUtilInternal::lastErrorToString();
}
OS::structstat buf;
if(OS::osstat(name, &buf) == -1)
{
- throw "cannot stat `" + name + "':\n" + IcePatch2::lastError();
+ throw "cannot stat `" + name + "':\n" + IceUtilInternal::lastErrorToString();
}
if(S_ISDIR(buf.st_mode))
diff --git a/cpp/src/IcePatch2/Calc.cpp b/cpp/src/IcePatch2/Calc.cpp
index be17981a6b6..17cfdd62739 100644
--- a/cpp/src/IcePatch2/Calc.cpp
+++ b/cpp/src/IcePatch2/Calc.cpp
@@ -9,6 +9,7 @@
#include <IceUtil/Options.h>
#include <IceUtil/Unicode.h>
+#include <IceUtil/StringUtil.h>
#include <IcePatch2/Util.h>
#include <OS.h>
@@ -191,7 +192,7 @@ main(int argc, char* argv[])
string cwd;
if(OS::getcwd(cwd) != 0)
{
- throw "cannot get the current directory:\n" + lastError();
+ throw "cannot get the current directory:\n" + IceUtilInternal::lastErrorToString();
}
if(!isAbsolute(absDataDir))
diff --git a/cpp/src/IcePatch2/ClientUtil.cpp b/cpp/src/IcePatch2/ClientUtil.cpp
index 07453c4af41..6ce8273a36f 100755
--- a/cpp/src/IcePatch2/ClientUtil.cpp
+++ b/cpp/src/IcePatch2/ClientUtil.cpp
@@ -8,6 +8,7 @@
// **********************************************************************
#include <IceUtil/Unicode.h>
+#include <IceUtil/StringUtil.h>
#include <IcePatch2/ClientUtil.h>
#include <IcePatch2/Util.h>
#include <IcePatch2/FileServerI.h>
@@ -79,7 +80,7 @@ public:
{
if(fputc('+', fp) == EOF || !writeFileInfo(fp, *p))
{
- throw "error writing log file:\n" + lastError();
+ throw "error writing log file:\n" + IceUtilInternal::lastErrorToString();
}
}
@@ -454,7 +455,7 @@ IcePatch2::Patcher::prepare()
_log = OS::fopen(pathLog, "w");
if(!_log)
{
- throw "cannot open `" + pathLog + "' for writing:\n" + lastError();
+ throw "cannot open `" + pathLog + "' for writing:\n" + IceUtilInternal::lastErrorToString();
}
return true;
@@ -614,7 +615,7 @@ IcePatch2::Patcher::init(const FileServerPrx& server)
string cwd;
if(OS::getcwd(cwd) != 0)
{
- throw "cannot get the current directory:\n" + lastError();
+ throw "cannot get the current directory:\n" + IceUtilInternal::lastErrorToString();
}
const_cast<string&>(_dataDir) = simplify(cwd + '/' + _dataDir);
}
@@ -638,7 +639,7 @@ IcePatch2::Patcher::removeFiles(const FileInfoSeq& files)
remove(_dataDir + '/' + p->path);
if(fputc('-', _log) == EOF || ! writeFileInfo(_log, *p))
{
- throw "error writing log file:\n" + lastError();
+ throw "error writing log file:\n" + IceUtilInternal::lastErrorToString();
}
}
catch(...)
@@ -797,7 +798,7 @@ IcePatch2::Patcher::updateFilesInternal(const FileInfoSeq& files, const Decompre
createDirectoryRecursive(_dataDir + '/' + p->path);
if(fputc('+', _log) == EOF || !writeFileInfo(_log, *p))
{
- throw "error writing log file:\n" + lastError();
+ throw "error writing log file:\n" + IceUtilInternal::lastErrorToString();
}
}
else // Regular file.
@@ -813,7 +814,7 @@ IcePatch2::Patcher::updateFilesInternal(const FileInfoSeq& files, const Decompre
FILE* fp = OS::fopen(path, "wb");
if(fp == 0)
{
- throw "cannot open `" + path +"' for writing:\n" + lastError();
+ throw "cannot open `" + path +"' for writing:\n" + IceUtilInternal::lastErrorToString();
}
fclose(fp);
}
@@ -838,7 +839,7 @@ IcePatch2::Patcher::updateFilesInternal(const FileInfoSeq& files, const Decompre
FILE* fileBZ2 = OS::fopen(pathBZ2, "wb");
if(fileBZ2 == 0)
{
- throw "cannot open `" + pathBZ2 + "' for writing:\n" + lastError();
+ throw "cannot open `" + pathBZ2 + "' for writing:\n" + IceUtilInternal::lastErrorToString();
}
try
@@ -897,7 +898,7 @@ IcePatch2::Patcher::updateFilesInternal(const FileInfoSeq& files, const Decompre
if(fwrite(reinterpret_cast<char*>(&bytes[0]), bytes.size(), 1, fileBZ2) != 1)
{
- throw ": cannot write `" + pathBZ2 + "':\n" + lastError();
+ throw ": cannot write `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString();
}
pos += static_cast<int>(bytes.size());
diff --git a/cpp/src/IcePatch2/Server.cpp b/cpp/src/IcePatch2/Server.cpp
index 35fe7589e48..2e34440611a 100644
--- a/cpp/src/IcePatch2/Server.cpp
+++ b/cpp/src/IcePatch2/Server.cpp
@@ -8,6 +8,7 @@
// **********************************************************************
#include <IceUtil/Options.h>
+#include <IceUtil/StringUtil.h>
#include <Ice/Service.h>
#include <IcePatch2/FileServerI.h>
#include <IcePatch2/Util.h>
@@ -122,7 +123,7 @@ IcePatch2::PatcherService::start(int argc, char* argv[])
string cwd;
if(OS::getcwd(cwd) != 0)
{
- throw "cannot get the current directory:\n" + lastError();
+ throw "cannot get the current directory:\n" + IceUtilInternal::lastErrorToString();
}
dataDir = cwd + '/' + dataDir;
diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp
index b756ab24bb6..85fd668470f 100644
--- a/cpp/src/IcePatch2/Util.cpp
+++ b/cpp/src/IcePatch2/Util.cpp
@@ -161,43 +161,6 @@ IcePatch2::readFileInfo(FILE* fp, FileInfo& info)
}
string
-IcePatch2::lastError()
-{
-#ifdef _WIN32
- LPVOID lpMsgBuf = 0;
- DWORD ok = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR)&lpMsgBuf,
- 0,
- NULL);
- if(ok)
- {
- LPCTSTR msg = (LPCTSTR)lpMsgBuf;
- assert(msg && strlen((const char*)msg) > 0);
- string result = (const char*)msg;
- LocalFree(lpMsgBuf);
-
- while(result.size() >= 1 && (result[result.size() - 1] == '\n' || result[result.size() - 1] == '\r'))
- {
- result.erase(result.size() - 1);
- }
-
- return result;
- }
- else
- {
- return "unknown error";
- }
-#else
- return strerror(errno);
-#endif
-}
-
-string
IcePatch2::bytesToString(const ByteSeq& bytes)
{
/*
@@ -454,7 +417,7 @@ IcePatch2::rename(const string& fromPa, const string& toPa)
if(OS::rename(fromPath ,toPath) == -1)
{
- throw "cannot rename `" + fromPath + "' to `" + toPath + "': " + lastError();
+ throw "cannot rename `" + fromPath + "' to `" + toPath + "': " + IceUtilInternal::lastErrorToString();
}
}
@@ -466,7 +429,7 @@ IcePatch2::remove(const string& pa)
OS::structstat buf;
if(OS::osstat(path, &buf) == -1)
{
- throw "cannot stat `" + path + "':\n" + lastError();
+ throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
if(S_ISDIR(buf.st_mode))
@@ -477,14 +440,14 @@ IcePatch2::remove(const string& pa)
{
assert(false);
}
- throw "cannot remove directory `" + path + "':\n" + lastError();
+ throw "cannot remove directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
}
else
{
if(OS::remove(path) == -1)
{
- throw "cannot remove file `" + path + "':\n" + lastError();
+ throw "cannot remove file `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
}
}
@@ -497,7 +460,7 @@ IcePatch2::removeRecursive(const string& pa)
OS::structstat buf;
if(OS::osstat(path, &buf) == -1)
{
- throw "cannot stat `" + path + "':\n" + lastError();
+ throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
if(S_ISDIR(buf.st_mode))
@@ -512,7 +475,7 @@ IcePatch2::removeRecursive(const string& pa)
{
if(OS::rmdir(path) == -1)
{
- throw "cannot remove directory `" + path + "':\n" + lastError();
+ throw "cannot remove directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
}
}
@@ -520,7 +483,7 @@ IcePatch2::removeRecursive(const string& pa)
{
if(OS::remove(path) == -1)
{
- throw "cannot remove file `" + path + "':\n" + lastError();
+ throw "cannot remove file `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
}
}
@@ -544,7 +507,7 @@ IcePatch2::readDirectory(const string& pa)
{
return result;
}
- throw "cannot read directory `" + path + "':\n" + lastError();
+ throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
@@ -565,7 +528,7 @@ IcePatch2::readDirectory(const string& pa)
break;
}
- string ex = "cannot read directory `" + path + "':\n" + lastError();
+ string ex = "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
_wfindclose(&data);
throw ex;
}
@@ -582,7 +545,7 @@ IcePatch2::readDirectory(const string& pa)
# endif
if(h == -1)
{
- throw "cannot read directory `" + path + "':\n" + lastError();
+ throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
while(true)
@@ -602,7 +565,7 @@ IcePatch2::readDirectory(const string& pa)
break;
}
- string ex = "cannot read directory `" + path + "':\n" + lastError();
+ string ex = "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
_findclose(h);
throw ex;
}
@@ -624,7 +587,7 @@ IcePatch2::readDirectory(const string& pa)
#endif
if(n < 0)
{
- throw "cannot read directory `" + path + "':\n" + lastError();
+ throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
StringSeq result;
@@ -658,7 +621,7 @@ IcePatch2::createDirectory(const string& pa)
{
if(errno != EEXIST)
{
- throw "cannot create directory `" + path + "':\n" + lastError();
+ throw "cannot create directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
}
}
@@ -689,7 +652,7 @@ IcePatch2::createDirectoryRecursive(const string& pa)
{
if(errno != EEXIST)
{
- throw "cannot create directory `" + path + "':\n" + lastError();
+ throw "cannot create directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
}
}
@@ -703,7 +666,7 @@ IcePatch2::compressBytesToFile(const string& pa, const ByteSeq& bytes, Int pos)
FILE* stdioFile = OS::fopen(path, "wb");
if(!stdioFile)
{
- throw "cannot open `" + path + "' for writing:\n" + lastError();
+ throw "cannot open `" + path + "' for writing:\n" + IceUtilInternal::lastErrorToString();
}
int bzError;
@@ -713,7 +676,7 @@ IcePatch2::compressBytesToFile(const string& pa, const ByteSeq& bytes, Int pos)
string ex = "BZ2_bzWriteOpen failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + lastError();
+ ex += string(": ") + IceUtilInternal::lastErrorToString();
}
fclose(stdioFile);
throw ex;
@@ -725,7 +688,7 @@ IcePatch2::compressBytesToFile(const string& pa, const ByteSeq& bytes, Int pos)
string ex = "BZ2_bzWrite failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + lastError();
+ ex += string(": ") + IceUtilInternal::lastErrorToString();
}
BZ2_bzWriteClose(&bzError, bzFile, 0, 0, 0);
fclose(stdioFile);
@@ -738,7 +701,7 @@ IcePatch2::compressBytesToFile(const string& pa, const ByteSeq& bytes, Int pos)
string ex = "BZ2_bzWriteClose failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + lastError();
+ ex += string(": ") + IceUtilInternal::lastErrorToString();
}
fclose(stdioFile);
throw ex;
@@ -763,13 +726,13 @@ IcePatch2::decompressFile(const string& pa)
fp = OS::fopen(path, "wb");
if(!fp)
{
- throw "cannot open `" + path + "' for writing:\n" + lastError();
+ throw "cannot open `" + path + "' for writing:\n" + IceUtilInternal::lastErrorToString();
}
stdioFileBZ2 = OS::fopen(pathBZ2, "rb");
if(!stdioFileBZ2)
{
- throw "cannot open `" + pathBZ2 + "' for reading:\n" + lastError();
+ throw "cannot open `" + pathBZ2 + "' for reading:\n" + IceUtilInternal::lastErrorToString();
}
#ifdef __BCPLUSPLUS__
@@ -779,13 +742,13 @@ IcePatch2::decompressFile(const string& pa)
OS::structstat buf;
if(OS::osstat(pathBZ2, &buf) == -1)
{
- throw "cannot stat `" + pathBZ2 + "':\n" + lastError();
+ throw "cannot stat `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString();
}
ByteSeq compressedBytes(buf.st_size);
if(fread(&compressedBytes[0], buf.st_size, 1, stdioFileBZ2) == -1)
{
- throw "cannot read from `" + pathBZ2 + "':\n" + lastError();
+ throw "cannot read from `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString();
}
ByteSeq uncompressedBytes;
@@ -809,7 +772,7 @@ IcePatch2::decompressFile(const string& pa)
string ex = "BZ2_bzBuffToBuffDecompress failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + lastError();
+ ex += string(": ") + IceUtilInternal::lastErrorToString();
}
throw ex;
}
@@ -817,7 +780,7 @@ IcePatch2::decompressFile(const string& pa)
if(fwrite(&uncompressedBytes[0], uncompressedLen, 1, fp) != 1)
{
- throw "cannot write to `" + path + "':\n" + lastError();
+ throw "cannot write to `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
#else
bzFile = BZ2_bzReadOpen(&bzError, stdioFileBZ2, 0, 0, 0, 0);
@@ -826,7 +789,7 @@ IcePatch2::decompressFile(const string& pa)
string ex = "BZ2_bzReadOpen failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + lastError();
+ ex += string(": ") + IceUtilInternal::lastErrorToString();
}
throw ex;
}
@@ -842,7 +805,7 @@ IcePatch2::decompressFile(const string& pa)
string ex = "BZ2_bzRead failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + lastError();
+ ex += string(": ") + IceUtilInternal::lastErrorToString();
}
throw ex;
}
@@ -852,12 +815,12 @@ IcePatch2::decompressFile(const string& pa)
long pos = ftell(stdioFileBZ2);
if(pos == -1)
{
- throw "cannot get read position for `" + pathBZ2 + "':\n" + lastError();
+ throw "cannot get read position for `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString();
}
if(fwrite(bytesBZ2, sz, 1, fp) != 1)
{
- throw "cannot write to `" + path + "':\n" + lastError();
+ throw "cannot write to `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
}
}
@@ -869,7 +832,7 @@ IcePatch2::decompressFile(const string& pa)
string ex = "BZ2_bzReadClose failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + lastError();
+ ex += string(": ") + IceUtilInternal::lastErrorToString();
}
throw ex;
}
@@ -904,7 +867,7 @@ IcePatch2::setFileFlags(const string& pa, const FileInfo& info)
OS::structstat buf;
if(OS::osstat(path, &buf) == -1)
{
- throw "cannot stat `" + path + "':\n" + lastError();
+ throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
chmod(path.c_str(), info.executable ? buf.st_mode | S_IXUSR : buf.st_mode & ~S_IXUSR);
#endif
@@ -950,7 +913,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
}
else
{
- throw "cannot stat `" + path + "':\n" + lastError();
+ throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
}
else if(buf.st_size == 0)
@@ -970,7 +933,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
OS::structstat buf;
if(OS::osstat(path, &buf) == -1)
{
- throw "cannot stat `" + path + "':\n" + lastError();
+ throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
if(S_ISDIR(buf.st_mode))
@@ -1073,7 +1036,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
int fd = OS::open(path.c_str(), O_BINARY|O_RDONLY);
if(fd == -1)
{
- throw "cannot open `" + path + "' for reading:\n" + lastError();
+ throw "cannot open `" + path + "' for reading:\n" + IceUtilInternal::lastErrorToString();
}
ByteSeq uncompressedBytes(buf.st_size);
@@ -1081,7 +1044,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
if(read(fd, &uncompressedBytes[0], buf.st_size) == -1)
{
close(fd);
- throw "cannot read from `" + path + "':\n" + lastError();
+ throw "cannot read from `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
unsigned int compressedLen = buf.st_size * 1.01 + 600;
@@ -1094,7 +1057,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
string ex = "BZ2_bzBuffToBuffCompress failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + lastError();
+ ex += string(": ") + IceUtilInternal::lastErrorToString();
}
close(fd);
throw ex;
@@ -1106,7 +1069,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
if(fwrite(&compressedBytes[0], compressedLen, 1, stdioFile) != 1)
{
fclose(stdioFile);
- throw "cannot write to `" + pathBZ2Temp + "':\n" + lastError();
+ throw "cannot write to `" + pathBZ2Temp + "':\n" + IceUtilInternal::lastErrorToString();
}
fclose(stdioFile);
@@ -1119,7 +1082,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
int fd = OS::open(path.c_str(), O_BINARY|O_RDONLY);
if(fd == -1)
{
- throw "cannot open `" + path + "' for reading:\n" + lastError();
+ throw "cannot open `" + path + "' for reading:\n" + IceUtilInternal::lastErrorToString();
}
#ifndef __BCPLUSPLUS__
@@ -1133,7 +1096,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
if(!stdioFile)
{
close(fd);
- throw "cannot open `" + pathBZ2Temp + "' for writing:\n" + lastError();
+ throw "cannot open `" + pathBZ2Temp + "' for writing:\n" + IceUtilInternal::lastErrorToString();
}
bzFile = BZ2_bzWriteOpen(&bzError, stdioFile, 5, 0, 0);
@@ -1142,7 +1105,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
string ex = "BZ2_bzWriteOpen failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + lastError();
+ ex += string(": ") + IceUtilInternal::lastErrorToString();
}
fclose(stdioFile);
close(fd);
@@ -1164,7 +1127,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
}
#endif
close(fd);
- throw "cannot read from `" + path + "':\n" + lastError();
+ throw "cannot read from `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
bytesLeft -= static_cast<unsigned int>(bytes.size());
@@ -1177,7 +1140,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
string ex = "BZ2_bzWrite failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + lastError();
+ ex += string(": ") + IceUtilInternal::lastErrorToString();
}
BZ2_bzWriteClose(&bzError, bzFile, 0, 0, 0);
fclose(stdioFile);
@@ -1201,7 +1164,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
string ex = "BZ2_bzWriteClose failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + lastError();
+ ex += string(": ") + IceUtilInternal::lastErrorToString();
}
fclose(stdioFile);
throw ex;
@@ -1213,7 +1176,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
if(OS::osstat(pathBZ2, &bufBZ2) == -1)
{
- throw "cannot stat `" + pathBZ2 + "':\n" + lastError();
+ throw "cannot stat `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString();
}
info.size = static_cast<Int>(bufBZ2.st_size);
@@ -1267,7 +1230,7 @@ IcePatch2::saveFileInfoSeq(const string& pa, const FileInfoSeq& infoSeq)
FILE* fp = OS::fopen(path, "w");
if(!fp)
{
- throw "cannot open `" + path + "' for writing:\n" + lastError();
+ throw "cannot open `" + path + "' for writing:\n" + IceUtilInternal::lastErrorToString();
}
try
{
@@ -1275,7 +1238,7 @@ IcePatch2::saveFileInfoSeq(const string& pa, const FileInfoSeq& infoSeq)
{
if(!writeFileInfo(fp, *p))
{
- throw "error writing `" + path + "':\n" + lastError();
+ throw "error writing `" + path + "':\n" + IceUtilInternal::lastErrorToString();
}
}
}
@@ -1309,7 +1272,7 @@ IcePatch2::loadFileInfoSeq(const string& pa, FileInfoSeq& infoSeq)
FILE* fp = OS::fopen(path, "r");
if(!fp)
{
- throw "cannot open `" + path + "' for reading:\n" + lastError();
+ throw "cannot open `" + path + "' for reading:\n" + IceUtilInternal::lastErrorToString();
}
while(true)
diff --git a/cpp/src/IceUtil/Exception.cpp b/cpp/src/IceUtil/Exception.cpp
index e893cb08397..cc8e8e0c4aa 100644
--- a/cpp/src/IceUtil/Exception.cpp
+++ b/cpp/src/IceUtil/Exception.cpp
@@ -9,6 +9,7 @@
#include <IceUtil/Exception.h>
#include <IceUtil/StaticMutex.h>
+#include <IceUtil/StringUtil.h>
#include <ostream>
#include <cstdlib>
@@ -148,7 +149,7 @@ IceUtil::IllegalArgumentException::IllegalArgumentException(const char* file, in
IceUtil::IllegalArgumentException::IllegalArgumentException(const char* file, int line, const string& r) :
Exception(file, line),
- reason(r)
+ _reason(r)
{
}
@@ -164,6 +165,13 @@ IceUtil::IllegalArgumentException::ice_name() const
return _name;
}
+void
+IceUtil::IllegalArgumentException::ice_print(ostream& out) const
+{
+ Exception::ice_print(out);
+ out << ": " << _reason;
+}
+
IceUtil::Exception*
IceUtil::IllegalArgumentException::ice_clone() const
{
@@ -176,10 +184,51 @@ IceUtil::IllegalArgumentException::ice_throw() const
throw *this;
}
-ostream&
-IceUtil::operator<<(ostream& out, const IceUtil::IllegalArgumentException& ex)
+string
+IceUtil::IllegalArgumentException::reason() const
{
- ex.ice_print(out);
- out << ": " << ex.reason;
- return out;
+ return _reason;
+}
+
+IceUtil::SyscallException::SyscallException(const char* file, int line, int err ):
+ Exception(file, line),
+ _error(err)
+{
+}
+
+const char* IceUtil::SyscallException::_name = "IceUtil::SyscallException";
+
+string
+IceUtil::SyscallException::ice_name() const
+{
+ return _name;
+}
+
+void
+IceUtil::SyscallException::ice_print(ostream& os) const
+{
+ Exception::ice_print(os);
+ if(_error != 0)
+ {
+ os << ":\nsyscall exception: " << IceUtilInternal::errorToString(_error);
+ }
}
+
+IceUtil::Exception*
+IceUtil::SyscallException::ice_clone() const
+{
+ return new SyscallException(*this);
+}
+
+void
+IceUtil::SyscallException::ice_throw() const
+{
+ throw *this;
+}
+
+int
+IceUtil::SyscallException::error() const
+{
+ return _error;
+}
+
diff --git a/cpp/src/IceUtil/Random.cpp b/cpp/src/IceUtil/Random.cpp
index d884dbb9a35..1712bb4394f 100644
--- a/cpp/src/IceUtil/Random.cpp
+++ b/cpp/src/IceUtil/Random.cpp
@@ -20,14 +20,6 @@
using namespace std;
using namespace IceUtil;
-IceUtilInternal::RandomGeneratorException::RandomGeneratorException(const char* file, int line, int error) :
- Exception(file, line),
- _error(error)
-{
-}
-
-const char* IceUtilInternal::RandomGeneratorException::_name = "IceUtilInternal::RandomGeneratorException";
-
//
// The static mutex is required to lazy initialize the file
// descriptor for /dev/urandom (Unix) or the cryptographic
@@ -78,60 +70,6 @@ public:
static RandomCleanup uuidCleanup;
}
-string
-IceUtilInternal::RandomGeneratorException::ice_name() const
-{
- return _name;
-}
-
-void
-IceUtilInternal::RandomGeneratorException::ice_print(ostream& os) const
-{
- Exception::ice_print(os);
- if(_error != 0)
- {
- os << ":\nrandom generator exception: ";
-#ifdef _WIN32
- LPVOID lpMsgBuf = 0;
- DWORD ok = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- _error,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR)&lpMsgBuf,
- 0,
- NULL);
-
- if(ok)
- {
- LPCTSTR msg = (LPCTSTR)lpMsgBuf;
- assert(msg && strlen((char*)msg) > 0);
- os << msg;
- LocalFree(lpMsgBuf);
- }
- else
- {
- os << "unknown random generator error";
- }
-#else
- os << strerror(_error);
-#endif
- }
-}
-
-Exception*
-IceUtilInternal::RandomGeneratorException::ice_clone() const
-{
- return new RandomGeneratorException(*this);
-}
-
-void
-IceUtilInternal::RandomGeneratorException::ice_throw() const
-{
- throw *this;
-}
-
void
IceUtilInternal::generateRandom(char* buffer, int size)
{
@@ -148,13 +86,13 @@ IceUtilInternal::generateRandom(char* buffer, int size)
{
if(!CryptAcquireContext(&context, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
{
- throw RandomGeneratorException(__FILE__, __LINE__, GetLastError());
+ throw SyscallException(__FILE__, __LINE__, GetLastError());
}
}
if(!CryptGenRandom(context, size, reinterpret_cast<unsigned char*>(buffer)))
{
- throw RandomGeneratorException(__FILE__, __LINE__, GetLastError());
+ throw SyscallException(__FILE__, __LINE__, GetLastError());
}
#else
@@ -168,7 +106,7 @@ IceUtilInternal::generateRandom(char* buffer, int size)
if(fd == -1)
{
assert(0);
- throw RandomGeneratorException(__FILE__, __LINE__);
+ throw SyscallException(__FILE__, __LINE__, errno);
}
}
@@ -184,10 +122,10 @@ IceUtilInternal::generateRandom(char* buffer, int size)
if(bytesRead == -1 && errno != EINTR)
{
- int err = errno;
- cerr << "Reading /dev/urandom returned " << strerror(err) << endl;
+ SyscallException ex(__FILE__, __LINE__, errno);
+ cerr << "Reading /dev/urandom failed:\n" << ex << endl;
assert(0);
- throw RandomGeneratorException(__FILE__, __LINE__, errno);
+ throw ex;
}
else
{
@@ -199,7 +137,7 @@ IceUtilInternal::generateRandom(char* buffer, int size)
if(index != static_cast<size_t>(size))
{
assert(0);
- throw RandomGeneratorException(__FILE__, __LINE__);
+ throw SyscallException(__FILE__, __LINE__, 0);
}
#endif
}
diff --git a/cpp/src/IceUtil/StringUtil.cpp b/cpp/src/IceUtil/StringUtil.cpp
index 8a96f795358..3f0806dfb0f 100644
--- a/cpp/src/IceUtil/StringUtil.cpp
+++ b/cpp/src/IceUtil/StringUtil.cpp
@@ -446,3 +446,227 @@ IceUtilInternal::match(const string& s, const string& pat, bool emptyMatch)
return true;
}
+
+#ifdef _WIN32
+
+string
+IceUtilInternal::errorToString(int error, LPCVOID source)
+{
+ if(error < WSABASEERR)
+ {
+ LPVOID lpMsgBuf = 0;
+ DWORD ok = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS |
+ (source != NULL ? FORMAT_MESSAGE_FROM_HMODULE : 0),
+ source,
+ error,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPTSTR)&lpMsgBuf,
+ 0,
+ NULL);
+ if(ok)
+ {
+ LPCTSTR msg = (LPCTSTR)lpMsgBuf;
+ assert(msg && strlen((const char*)msg) > 0);
+ string result = (const char*)msg;
+ if(result[result.length() - 1] == '\n')
+ {
+ result = result.substr(0, result.length() - 2);
+ }
+ LocalFree(lpMsgBuf);
+ return result;
+ }
+ else
+ {
+ ostringstream os;
+ os << "unknown error: " << error;
+ return os.str();
+ }
+ }
+
+ switch(error)
+ {
+ case WSAEINTR:
+ return "WSAEINTR";
+
+ case WSAEBADF:
+ return "WSAEBADF";
+
+ case WSAEACCES:
+ return "WSAEACCES";
+
+ case WSAEFAULT:
+ return "WSAEFAULT";
+
+ case WSAEINVAL:
+ return "WSAEINVAL";
+
+ case WSAEMFILE:
+ return "WSAEMFILE";
+
+ case WSAEWOULDBLOCK:
+ return "WSAEWOULDBLOCK";
+
+ case WSAEINPROGRESS:
+ return "WSAEINPROGRESS";
+
+ case WSAEALREADY:
+ return "WSAEALREADY";
+
+ case WSAENOTSOCK:
+ return "WSAENOTSOCK";
+
+ case WSAEDESTADDRREQ:
+ return "WSAEDESTADDRREQ";
+
+ case WSAEMSGSIZE:
+ return "WSAEMSGSIZE";
+
+ case WSAEPROTOTYPE:
+ return "WSAEPROTOTYPE";
+
+ case WSAENOPROTOOPT:
+ return "WSAENOPROTOOPT";
+
+ case WSAEPROTONOSUPPORT:
+ return "WSAEPROTONOSUPPORT";
+
+ case WSAESOCKTNOSUPPORT:
+ return "WSAESOCKTNOSUPPORT";
+
+ case WSAEOPNOTSUPP:
+ return "WSAEOPNOTSUPP";
+
+ case WSAEPFNOSUPPORT:
+ return "WSAEPFNOSUPPORT";
+
+ case WSAEAFNOSUPPORT:
+ return "WSAEAFNOSUPPORT";
+
+ case WSAEADDRINUSE:
+ return "WSAEADDRINUSE";
+
+ case WSAEADDRNOTAVAIL:
+ return "WSAEADDRNOTAVAIL";
+
+ case WSAENETDOWN:
+ return "WSAENETDOWN";
+
+ case WSAENETUNREACH:
+ return "WSAENETUNREACH";
+
+ case WSAENETRESET:
+ return "WSAENETRESET";
+
+ case WSAECONNABORTED:
+ return "WSAECONNABORTED";
+
+ case WSAECONNRESET:
+ return "WSAECONNRESET";
+
+ case WSAENOBUFS:
+ return "WSAENOBUFS";
+
+ case WSAEISCONN:
+ return "WSAEISCONN";
+
+ case WSAENOTCONN:
+ return "WSAENOTCONN";
+
+ case WSAESHUTDOWN:
+ return "WSAESHUTDOWN";
+
+ case WSAETOOMANYREFS:
+ return "WSAETOOMANYREFS";
+
+ case WSAETIMEDOUT:
+ return "WSAETIMEDOUT";
+
+ case WSAECONNREFUSED:
+ return "WSAECONNREFUSED";
+
+ case WSAELOOP:
+ return "WSAELOOP";
+
+ case WSAENAMETOOLONG:
+ return "WSAENAMETOOLONG";
+
+ case WSAEHOSTDOWN:
+ return "WSAEHOSTDOWN";
+
+ case WSAEHOSTUNREACH:
+ return "WSAEHOSTUNREACH";
+
+ case WSAENOTEMPTY:
+ return "WSAENOTEMPTY";
+
+ case WSAEPROCLIM:
+ return "WSAEPROCLIM";
+
+ case WSAEUSERS:
+ return "WSAEUSERS";
+
+ case WSAEDQUOT:
+ return "WSAEDQUOT";
+
+ case WSAESTALE:
+ return "WSAESTALE";
+
+ case WSAEREMOTE:
+ return "WSAEREMOTE";
+
+ case WSAEDISCON:
+ return "WSAEDISCON";
+
+ case WSASYSNOTREADY:
+ return "WSASYSNOTREADY";
+
+ case WSAVERNOTSUPPORTED:
+ return "WSAVERNOTSUPPORTED";
+
+ case WSANOTINITIALISED:
+ return "WSANOTINITIALISED";
+
+ case WSAHOST_NOT_FOUND:
+ return "WSAHOST_NOT_FOUND";
+
+ case WSATRY_AGAIN:
+ return "WSATRY_AGAIN";
+
+ case WSANO_RECOVERY:
+ return "WSANO_RECOVERY";
+
+ case WSANO_DATA:
+ return "WSANO_DATA";
+
+ default:
+ {
+ ostringstream os;
+ os << "unknown socket error: " << error;
+ return os.str();
+ }
+ }
+}
+
+string
+IceUtilInternal::lastErrorToString()
+{
+ return errorToString(GetLastError());
+}
+
+#else
+
+string
+IceUtilInternal::errorToString(int error)
+{
+ return strerror(error);
+}
+
+string
+IceUtilInternal::lastErrorToString()
+{
+ return errorToString(errno);
+}
+
+#endif
diff --git a/cpp/src/IceUtil/ThreadException.cpp b/cpp/src/IceUtil/ThreadException.cpp
index 7a17a98185e..c24eae6754c 100644
--- a/cpp/src/IceUtil/ThreadException.cpp
+++ b/cpp/src/IceUtil/ThreadException.cpp
@@ -12,8 +12,7 @@
using namespace std;
IceUtil::ThreadSyscallException::ThreadSyscallException(const char* file, int line, int err ):
- Exception(file, line),
- _error(err)
+ SyscallException(file, line, err)
{
}
@@ -25,42 +24,6 @@ IceUtil::ThreadSyscallException::ice_name() const
return _name;
}
-void
-IceUtil::ThreadSyscallException::ice_print(ostream& os) const
-{
- Exception::ice_print(os);
- if(_error != 0)
- {
- os << ":\nthread syscall exception: ";
-#ifdef _WIN32
- LPVOID lpMsgBuf = 0;
- DWORD ok = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- _error,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR)&lpMsgBuf,
- 0,
- NULL);
-
- if(ok)
- {
- LPCTSTR msg = (LPCTSTR)lpMsgBuf;
- assert(msg && strlen((char*)msg) > 0);
- os << msg;
- LocalFree(lpMsgBuf);
- }
- else
- {
- os << "unknown thread error";
- }
-#else
- os << strerror(_error);
-#endif
- }
-}
-
IceUtil::Exception*
IceUtil::ThreadSyscallException::ice_clone() const
{
@@ -73,13 +36,6 @@ IceUtil::ThreadSyscallException::ice_throw() const
throw *this;
}
-int
-IceUtil::ThreadSyscallException::error() const
-{
- return _error;
-}
-
-
IceUtil::ThreadLockedException::ThreadLockedException(const char* file, int line) :
Exception(file, line)
{
diff --git a/cpp/src/IceUtil/Time.cpp b/cpp/src/IceUtil/Time.cpp
index d562d7a72b4..0c747fb7104 100644
--- a/cpp/src/IceUtil/Time.cpp
+++ b/cpp/src/IceUtil/Time.cpp
@@ -8,6 +8,7 @@
// **********************************************************************
#include <IceUtil/DisableWarnings.h>
+#include <IceUtil/Exception.h>
#include <IceUtil/Time.h>
#include <iomanip>
@@ -20,15 +21,48 @@
using namespace IceUtil;
+#ifdef _WIN32
+
+namespace
+{
+
+static double frequency = -1.0;
+
+//
+// Initialize the frequency
+//
+class InitializeFrequency
+{
+public:
+
+ InitializeFrequency()
+ {
+ //
+ // Get the frequency of performance counters. We also make a call to
+ // QueryPerformanceCounter to ensure it works. If it fails or if the
+ // call to QueryPerformanceFrequency fails, the frequency will remain
+ // set to -1.0 and ftime will be used instead.
+ //
+ Int64 v;
+ if(QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&v)))
+ {
+ if(QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(&v)))
+ {
+ frequency = static_cast<double>(v);
+ }
+ }
+ }
+};
+static InitializeFrequency frequencyInitializer;
+
+};
+#endif
+
Time::Time() :
_usec(0)
{
}
-#ifdef _WIN32
-Int64 IceUtil::Time::_frequency = -1;
-#endif
-
Time
IceUtil::Time::now(Clock clock)
{
@@ -42,38 +76,59 @@ IceUtil::Time::now(Clock clock)
struct timeb tb;
ftime(&tb);
# endif
- return Time(static_cast<Int64>(tb.time) * ICE_INT64(1000000) +
- tb.millitm * 1000);
+ return Time(static_cast<Int64>(tb.time) * ICE_INT64(1000000) + tb.millitm * 1000);
#else
struct timeval tv;
- gettimeofday(&tv, 0);
+ if(gettimeofday(&tv, 0) < 0)
+ {
+ assert(0);
+ throw SyscallException(__FILE__, __LINE__, errno);
+ }
return Time(tv.tv_sec * ICE_INT64(1000000) + tv.tv_usec);
#endif
}
else // Monotonic
{
#if defined(_WIN32)
- if(_frequency == -1)
+ if(frequency > 0.0)
+ {
+ Int64 count;
+ if(!QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&count)))
+ {
+ assert(0);
+ throw SyscallException(__FILE__, __LINE__, GetLastError());
+ }
+ return Time(static_cast<Int64>(count / frequency * 1000000.0));
+ }
+ else
{
- //
- // Frequency cannot change while machine is running so it
- // only needs to be retrieved once.
- //
- QueryPerformanceFrequency((LARGE_INTEGER*)&_frequency);
+# if defined(_MSC_VER)
+ struct _timeb tb;
+ _ftime(&tb);
+# elif defined(__BCPLUSPLUS__)
+ struct timeb tb;
+ ftime(&tb);
+# endif
+ return Time(static_cast<Int64>(tb.time) * ICE_INT64(1000000) + tb.millitm * 1000);
}
- Int64 count;
- QueryPerformanceCounter((LARGE_INTEGER*)&count);
- return Time((Int64)(1000000.0 / _frequency * count));
#elif defined(__hpux) || defined(__APPLE__)
//
// HP/MacOS does not support CLOCK_MONOTONIC
//
struct timeval tv;
- gettimeofday(&tv, 0);
+ if(gettimeofday(&tv, 0) < 0)
+ {
+ assert(0);
+ throw SyscallException(__FILE__, __LINE__, errno);
+ }
return Time(tv.tv_sec * ICE_INT64(1000000) + tv.tv_usec);
#else
struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
+ if(clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
+ {
+ assert(0);
+ throw SyscallException(__FILE__, __LINE__, errno);
+ }
return Time(ts.tv_sec * ICE_INT64(1000000) + ts.tv_nsec / ICE_INT64(1000));
#endif
}
diff --git a/cpp/src/iceserviceinstall/ServiceInstaller.cpp b/cpp/src/iceserviceinstall/ServiceInstaller.cpp
index 8ed93fc16a2..43c73eaeafc 100755
--- a/cpp/src/iceserviceinstall/ServiceInstaller.cpp
+++ b/cpp/src/iceserviceinstall/ServiceInstaller.cpp
@@ -14,6 +14,7 @@
#endif
#include <ServiceInstaller.h>
+#include <IceUtil/StringUtil.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -130,7 +131,7 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
DWORD size = GetModuleFileName(0, buffer, MAX_PATH);
if(size == 0)
{
- throw "Can't get full path to self: " + formatMessage(GetLastError());
+ throw "Can't get full path to self: " + IceUtilInternal::errorToString(GetLastError());
}
imagePath = string(buffer, size);
imagePath.replace(imagePath.rfind('\\'), string::npos, "\\"
@@ -214,7 +215,7 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
if(scm == 0)
{
DWORD res = GetLastError();
- throw "Cannot open SCM: " + formatMessage(res);
+ throw "Cannot open SCM: " + IceUtilInternal::errorToString(res);
}
string deps = dependency;
@@ -272,7 +273,7 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
{
DWORD res = GetLastError();
CloseServiceHandle(scm);
- throw "Cannot create service" + _serviceName + ": " + formatMessage(res);
+ throw "Cannot create service" + _serviceName + ": " + IceUtilInternal::errorToString(res);
}
//
@@ -286,8 +287,7 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
DWORD res = GetLastError();
CloseServiceHandle(scm);
CloseServiceHandle(service);
- throw "Cannot set description for service" + _serviceName + ": "
- + formatMessage(res);
+ throw "Cannot set description for service" + _serviceName + ": " + IceUtilInternal::errorToString(res);
}
CloseServiceHandle(scm);
@@ -301,7 +301,7 @@ IceServiceInstaller::uninstall()
if(scm == 0)
{
DWORD res = GetLastError();
- throw "Cannot open SCM: " + formatMessage(res);
+ throw "Cannot open SCM: " + IceUtilInternal::errorToString(res);
}
SC_HANDLE service = OpenService(scm, _serviceName.c_str(), SERVICE_ALL_ACCESS);
@@ -309,7 +309,7 @@ IceServiceInstaller::uninstall()
{
DWORD res = GetLastError();
CloseServiceHandle(scm);
- throw "Cannot open service '" + _serviceName + "': " + formatMessage(res);
+ throw "Cannot open service '" + _serviceName + "': " + IceUtilInternal::errorToString(res);
}
//
@@ -323,7 +323,7 @@ IceServiceInstaller::uninstall()
{
CloseServiceHandle(scm);
CloseServiceHandle(service);
- throw "Cannot stop service '" + _serviceName + "': " + formatMessage(res);
+ throw "Cannot stop service '" + _serviceName + "': " + IceUtilInternal::errorToString(res);
}
}
@@ -332,7 +332,7 @@ IceServiceInstaller::uninstall()
DWORD res = GetLastError();
CloseServiceHandle(scm);
CloseServiceHandle(service);
- throw "Cannot delete service '" + _serviceName + "': " + formatMessage(res);
+ throw "Cannot delete service '" + _serviceName + "': " + IceUtilInternal::errorToString(res);
}
CloseServiceHandle(scm);
@@ -418,8 +418,7 @@ IceServiceInstaller::initializeSid(const string& name)
_sid = 0;
free(domainName);
- throw "Could not retrieve Security ID for " + name + ": "
- + formatMessage(res);
+ throw "Could not retrieve Security ID for " + name + ": " + IceUtilInternal::errorToString(res);
}
}
free(domainName);
@@ -452,8 +451,7 @@ IceServiceInstaller::initializeSid(const string& name)
&domainLen, &nameUse) == false)
{
DWORD res = GetLastError();
- throw "Could not retrieve full account name for " + name + ": "
- + formatMessage(res);
+ throw "Could not retrieve full account name for " + name + ": " + IceUtilInternal::errorToString(res);
}
_sidName = string(domainName) + "\\" + accountName;
@@ -515,8 +513,7 @@ IceServiceInstaller::grantPermissions(const string& path, SE_OBJECT_TYPE type, b
0, 0, &acl, 0, &sd);
if(res != ERROR_SUCCESS)
{
- throw "Could not retrieve securify info for " + path + ": "
- + formatMessage(res);
+ throw "Could not retrieve securify info for " + path + ": " + IceUtilInternal::errorToString(res);
}
try
@@ -532,8 +529,7 @@ IceServiceInstaller::grantPermissions(const string& path, SE_OBJECT_TYPE type, b
if(res != ERROR_SUCCESS)
{
- throw "Could not retrieve effective rights for " + _sidName
- + " on " + path + ": " + formatMessage(res);
+ throw "Could not retrieve effective rights for " + _sidName + " on " + path + ": " + IceUtilInternal::errorToString(res);
}
bool done = false;
@@ -593,7 +589,7 @@ IceServiceInstaller::grantPermissions(const string& path, SE_OBJECT_TYPE type, b
res = SetEntriesInAcl(1, &ea, acl, &newAcl);
if(res != ERROR_SUCCESS)
{
- throw "Could not modify ACL for " + path + ": " + formatMessage(res);
+ throw "Could not modify ACL for " + path + ": " + IceUtilInternal::errorToString(res);
}
res = SetNamedSecurityInfo(const_cast<char*>(path.c_str()), type,
@@ -601,8 +597,7 @@ IceServiceInstaller::grantPermissions(const string& path, SE_OBJECT_TYPE type, b
0, 0, newAcl, 0);
if(res != ERROR_SUCCESS)
{
- throw "Could not grant access to " + _sidName
- + " on " + path + ": " + formatMessage(res);
+ throw "Could not grant access to " + _sidName + " on " + path + ": " + IceUtilInternal::errorToString(res);
}
if(_debug)
@@ -642,7 +637,7 @@ IceServiceInstaller::mkdir(const string& path) const
}
else
{
- throw "Could not create directory " + path + ": " + formatMessage(res);
+ throw "Could not create directory " + path + ": " + IceUtilInternal::errorToString(res);
}
}
else
@@ -652,34 +647,6 @@ IceServiceInstaller::mkdir(const string& path) const
}
}
-string
-IceServiceInstaller::formatMessage(DWORD err) const
-{
- ostringstream os;
- char* msgBuf = 0;
- DWORD ok = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- 0,
- err,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- reinterpret_cast<char*>(&msgBuf),
- 0,
- 0);
-
- if(ok)
- {
- os << msgBuf;
- LocalFree(msgBuf);
- }
- else
- {
- os << "unknown error";
- }
-
- return os.str();
-}
-
void
IceServiceInstaller::addLog(const string& log) const
{
@@ -695,13 +662,13 @@ IceServiceInstaller::addLog(const string& log) const
if(res != ERROR_SUCCESS)
{
- throw "Could not create new Event Log '" + log + "': " + formatMessage(res);
+ throw "Could not create new Event Log '" + log + "': " + IceUtilInternal::errorToString(res);
}
res = RegCloseKey(key);
if(res != ERROR_SUCCESS)
{
- throw "Could not close registry key handle: " + formatMessage(res);
+ throw "Could not close registry key handle: " + IceUtilInternal::errorToString(res);
}
}
@@ -715,7 +682,7 @@ IceServiceInstaller::removeLog(const string& log) const
//
if(res != ERROR_SUCCESS && res != ERROR_ACCESS_DENIED)
{
- throw "Could not remove registry key '" + createLog(log) + "': " + formatMessage(res);
+ throw "Could not remove registry key '" + createLog(log) + "': " + IceUtilInternal::errorToString(res);
}
}
@@ -729,7 +696,7 @@ IceServiceInstaller::addSource(const string& source, const string& log, const st
&key, &disposition);
if(res != ERROR_SUCCESS)
{
- throw "Could not create Event Log source in registry: " + formatMessage(res);
+ throw "Could not create Event Log source in registry: " + IceUtilInternal::errorToString(res);
}
//
@@ -756,13 +723,13 @@ IceServiceInstaller::addSource(const string& source, const string& log, const st
if(res != ERROR_SUCCESS)
{
RegCloseKey(key);
- throw "Could not set registry key: " + formatMessage(res);
+ throw "Could not set registry key: " + IceUtilInternal::errorToString(res);
}
res = RegCloseKey(key);
if(res != ERROR_SUCCESS)
{
- throw "Could not close registry key handle: " + formatMessage(res);
+ throw "Could not close registry key handle: " + IceUtilInternal::errorToString(res);
}
}
@@ -780,7 +747,7 @@ IceServiceInstaller::removeSource(const string& source) const
if(res != ERROR_SUCCESS)
{
- throw "Could not open EventLog key: " + formatMessage(res);
+ throw "Could not open EventLog key: " + IceUtilInternal::errorToString(res);
}
DWORD index = 0;
@@ -802,7 +769,7 @@ IceServiceInstaller::removeSource(const string& source) const
res = RegCloseKey(key);
if(res != ERROR_SUCCESS)
{
- throw "Could not close registry key handle: " + formatMessage(res);
+ throw "Could not close registry key handle: " + IceUtilInternal::errorToString(res);
}
return subkey;
}
@@ -820,13 +787,13 @@ IceServiceInstaller::removeSource(const string& source) const
else
{
RegCloseKey(key);
- throw "Error while searching EventLog with source '" + source + "': " + formatMessage(res);
+ throw "Error while searching EventLog with source '" + source + "': " + IceUtilInternal::errorToString(res);
}
res = RegCloseKey(key);
if(res != ERROR_SUCCESS)
{
- throw "Could not close registry key handle: " + formatMessage(res);
+ throw "Could not close registry key handle: " + IceUtilInternal::errorToString(res);
}
}
diff --git a/cpp/src/iceserviceinstall/ServiceInstaller.h b/cpp/src/iceserviceinstall/ServiceInstaller.h
index 88c3edea2d7..94b1aeaf7fa 100755
--- a/cpp/src/iceserviceinstall/ServiceInstaller.h
+++ b/cpp/src/iceserviceinstall/ServiceInstaller.h
@@ -57,7 +57,6 @@ private:
void grantPermissions(const std::string& path, SE_OBJECT_TYPE type = SE_FILE_OBJECT,
bool inherit = false, bool fullControl = false) const;
bool mkdir(const std::string&) const;
- std::string formatMessage(DWORD) const;
void addLog(const std::string&) const;
void removeLog(const std::string&) const;
diff --git a/cpp/src/slice2html/Main.cpp b/cpp/src/slice2html/Main.cpp
index 6ca031ae35b..3cb0ff90778 100644
--- a/cpp/src/slice2html/Main.cpp
+++ b/cpp/src/slice2html/Main.cpp
@@ -125,7 +125,7 @@ main(int argc, char* argv[])
string indexFooter = opts.optArg("indexftr");
string ind = opts.optArg("index");
- unsigned indexCount;
+ unsigned indexCount = 0;
if(!ind.empty())
{
istringstream s(ind);
@@ -145,7 +145,7 @@ main(int argc, char* argv[])
string searchAction = opts.optArg("search");
string warnSummary = opts.optArg("summary");
- unsigned summaryCount;
+ unsigned summaryCount = 0;
if(!warnSummary.empty())
{
istringstream s(warnSummary);