MCPcopy Create free account
hub / github.com/cuberite/cuberite / GetOSErrorString

Function GetOSErrorString

src/OSSupport/Errors.cpp:6–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include "Errors.h"
5
6AString GetOSErrorString( int a_ErrNo )
7{
8 char buffer[ 1024 ];
9 AString Out;
10
11 #ifdef _WIN32
12
13 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, a_ErrNo, 0, buffer, ARRAYCOUNT(buffer), NULL);
14 Printf(Out, "%d: %s", a_ErrNo, buffer);
15 if (!Out.empty() && (Out[Out.length() - 1] == '\n'))
16 {
17 Out.erase(Out.length() - 2);
18 }
19 return Out;
20
21 #else // _WIN32
22
23 // According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r():
24
25 #if !defined(__APPLE__) && ( _GNU_SOURCE ) && !defined(ANDROID_NDK) // GNU version of strerror_r()
26
27 char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) );
28 if( res != NULL )
29 {
30 Printf(Out, "%d: %s", a_ErrNo, res);
31 return Out;
32 }
33
34 #else // XSI version of strerror_r():
35
36 int res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) );
37 if( res == 0 )
38 {
39 Printf(Out, "%d: %s", a_ErrNo, buffer);
40 return Out;
41 }
42
43 #endif // strerror_r() version
44
45 else
46 {
47 Printf(Out, "Error %d while getting error string for error #%d!", errno, a_ErrNo);
48 return Out;
49 }
50
51 #endif // else _WIN32
52}
53

Callers 7

ConnectMethod · 0.85
WriteToSocketsMethod · 0.85
GetLastErrorStringMethod · 0.85
cEventMethod · 0.85
~cEventMethod · 0.85
WaitMethod · 0.85
SetMethod · 0.85

Calls 2

PrintfFunction · 0.85
emptyMethod · 0.80

Tested by

no test coverage detected