summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/Errors.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-01-25 19:43:00 +0100
committerMattes D <github@xoft.cz>2014-01-25 19:43:00 +0100
commitc8be9b5b1aa152e61ca61870c0f95313571e1918 (patch)
tree93be710bd8884e526ff719b4302fd2eb4569b66c /src/OSSupport/Errors.cpp
parentComm logging is available in both Debug and Release modes. (diff)
parentSwitched cEvent to GetOSErrorString (diff)
downloadcuberite-c8be9b5b1aa152e61ca61870c0f95313571e1918.tar
cuberite-c8be9b5b1aa152e61ca61870c0f95313571e1918.tar.gz
cuberite-c8be9b5b1aa152e61ca61870c0f95313571e1918.tar.bz2
cuberite-c8be9b5b1aa152e61ca61870c0f95313571e1918.tar.lz
cuberite-c8be9b5b1aa152e61ca61870c0f95313571e1918.tar.xz
cuberite-c8be9b5b1aa152e61ca61870c0f95313571e1918.tar.zst
cuberite-c8be9b5b1aa152e61ca61870c0f95313571e1918.zip
Diffstat (limited to 'src/OSSupport/Errors.cpp')
-rw-r--r--src/OSSupport/Errors.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/OSSupport/Errors.cpp b/src/OSSupport/Errors.cpp
new file mode 100644
index 000000000..2e05f1df1
--- /dev/null
+++ b/src/OSSupport/Errors.cpp
@@ -0,0 +1,53 @@
+
+#include "Globals.h"
+
+#include "Errors.h"
+
+AString GetOSErrorString( int a_ErrNo )
+{
+ char buffer[ 1024 ];
+ AString Out;
+
+ #ifdef _WIN32
+
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, a_ErrNo, 0, buffer, ARRAYCOUNT(buffer), NULL);
+ Printf(Out, "%d: %s", a_ErrNo, buffer);
+ if (!Out.empty() && (Out[Out.length() - 1] == '\n'))
+ {
+ Out.erase(Out.length() - 2);
+ }
+ return Out;
+
+ #else // _WIN32
+
+ // According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r():
+
+ #if ( _GNU_SOURCE ) && !defined(ANDROID_NDK) // GNU version of strerror_r()
+
+ char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) );
+ if( res != NULL )
+ {
+ Printf(Out, "%d: %s", a_ErrNo, res);
+ return Out;
+ }
+
+ #else // XSI version of strerror_r():
+
+ int res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) );
+ if( res == 0 )
+ {
+ Printf(Out, "%d: %s", a_ErrNo, buffer);
+ return Out;
+ }
+
+ #endif // strerror_r() version
+
+ else
+ {
+ Printf(Out, "Error %d while getting error string for error #%d!", errno, a_ErrNo);
+ return Out;
+ }
+
+ #endif // else _WIN32
+}
+