diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-06 14:22:28 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-06 14:22:28 +0100 |
commit | 12fd317a7bd8bc6c24d034227076fbe87dfe6e31 (patch) | |
tree | efb62fc7bfcaf2d5ec9c24928f59af1a89ef091a | |
parent | cSocket: re-implemented the GetLastErrorString() function; win: error texts are now queried from the system rather than enumerated by the program (diff) | |
download | cuberite-12fd317a7bd8bc6c24d034227076fbe87dfe6e31.tar cuberite-12fd317a7bd8bc6c24d034227076fbe87dfe6e31.tar.gz cuberite-12fd317a7bd8bc6c24d034227076fbe87dfe6e31.tar.bz2 cuberite-12fd317a7bd8bc6c24d034227076fbe87dfe6e31.tar.lz cuberite-12fd317a7bd8bc6c24d034227076fbe87dfe6e31.tar.xz cuberite-12fd317a7bd8bc6c24d034227076fbe87dfe6e31.tar.zst cuberite-12fd317a7bd8bc6c24d034227076fbe87dfe6e31.zip |
Diffstat (limited to '')
-rw-r--r-- | source/cSocket.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/source/cSocket.cpp b/source/cSocket.cpp index bb6f68249..323ed59c8 100644 --- a/source/cSocket.cpp +++ b/source/cSocket.cpp @@ -94,22 +94,43 @@ void cSocket::CloseSocket() AString cSocket::GetErrorString( int a_ErrNo )
{
+ char buffer[ 1024 ];
+ AString Out;
+
#ifdef _WIN32
- char Buffer[1024];
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, a_ErrNo, 0, Buffer, ARRAYCOUNT(Buffer), NULL);
- return AString(Buffer);
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, a_ErrNo, 0, buffer, ARRAYCOUNT(buffer), NULL);
+ Printf(Out, "%d: %s", a_ErrNo, buffer);
+ return Out;
#else // _WIN32
-
- char buffer[ 256 ];
- if( strerror_r( errno, buffer, 256 ) == 0 )
+
+ // According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r():
+
+ #if (((_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600)) && ! _GNU_SOURCE) // XSI version of strerror_r():
+
+ int res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) );
+ if( res == 0 )
{
- return AString( buffer );
+ Printf(Out, "%d: %s", a_ErrNo, buffer);
+ return Out;
}
+
+ #else // 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;
+ }
+
+ #endif // strerror_r() version
+
else
{
- return "Error on getting error string!";
+ Printf(Out, "Error %d while getting error string for error #%d!", errno, a_ErrNo);
+ return Out;
}
#endif // else _WIN32
|