summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/StringUtil.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2018-07-27 13:55:58 +0200
committerJose <jose@zeroc.com>2018-07-27 13:55:58 +0200
commit83b85371785bae2928332ac758f2359b724ef420 (patch)
treede77474c09aeb5c2038286216578bbc628801734 /cpp/src/IceUtil/StringUtil.cpp
parentFix UWP Build failure (diff)
downloadice-83b85371785bae2928332ac758f2359b724ef420.tar.bz2
ice-83b85371785bae2928332ac758f2359b724ef420.tar.xz
ice-83b85371785bae2928332ac758f2359b724ef420.zip
Replace strerror usage with IceUtilInternal::errorToString
Close #154
Diffstat (limited to 'cpp/src/IceUtil/StringUtil.cpp')
-rw-r--r--cpp/src/IceUtil/StringUtil.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/cpp/src/IceUtil/StringUtil.cpp b/cpp/src/IceUtil/StringUtil.cpp
index c1c9099e215..3ecbe9ebd99 100644
--- a/cpp/src/IceUtil/StringUtil.cpp
+++ b/cpp/src/IceUtil/StringUtil.cpp
@@ -10,7 +10,9 @@
#include <IceUtil/StringUtil.h>
#include <IceUtil/StringConverter.h>
#include <cstring>
+#include <string.h> // for strerror_r
+#include <sstream>
#include <iomanip>
using namespace std;
@@ -1071,7 +1073,38 @@ IceUtilInternal::lastErrorToString()
string
IceUtilInternal::errorToString(int error)
{
- return strerror(error);
+ char buf[500];
+#if !defined(__GLIBC__) || defined(BSD) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE)
+ //
+ // Use the XSI-compliant version of strerror_r
+ //
+ if(strerror_r(error, &buf[0], 500) != 0)
+ {
+ ostringstream os;
+ os << "Unknown error `" << error << "'";
+ return os.str();
+ }
+ else
+ {
+ return string(buf);
+ }
+#else
+ //
+ // Use the GNU-specific version of strerror_r
+ //
+ errno = 0;
+ const char* msg = strerror_r(error, &buf[0], 500);
+ if(errno != 0)
+ {
+ ostringstream os;
+ os << "Unknown error `" << error << "'";
+ return os.str();
+ }
+ else
+ {
+ return msg;
+ }
+#endif
}
string