initialize the error buffer for gnu strerror_r
This commit is contained in:
parent
1173e00f19
commit
e8d2885728
@ -41,15 +41,29 @@ using std::string;
|
|||||||
static void caterrno(string *reason, const char *what, int _errno)
|
static void caterrno(string *reason, const char *what, int _errno)
|
||||||
{
|
{
|
||||||
if (reason) {
|
if (reason) {
|
||||||
reason->append("file_to_string: ");
|
|
||||||
reason->append(what);
|
reason->append(what);
|
||||||
reason->append(": ");
|
reason->append(": errno: ");
|
||||||
|
char nbuf[10];
|
||||||
|
sprintf(nbuf, "%d", _errno);
|
||||||
|
reason->append(nbuf);
|
||||||
|
reason->append(" : ");
|
||||||
#ifdef sun
|
#ifdef sun
|
||||||
// Note: sun strerror is noted mt-safe ??
|
// Note: sun strerror is noted mt-safe ??
|
||||||
reason->append(strerror(_errno));
|
reason->append(strerror(_errno));
|
||||||
#else
|
#else
|
||||||
#define ERRBUFSZ 200
|
#define ERRBUFSZ 200
|
||||||
char errbuf[ERRBUFSZ];
|
char errbuf[ERRBUFSZ];
|
||||||
|
// There are 2 versions of strerror_r.
|
||||||
|
// - The GNU one returns a pointer to the message (maybe
|
||||||
|
// static storage or supplied buffer).
|
||||||
|
// - The POSIX one always stores in supplied buffer and
|
||||||
|
// returns 0 on success. As the possibility of error and
|
||||||
|
// error code are not specified, we're basically doomed
|
||||||
|
// cause we can't use a test on the 0 value to know if we
|
||||||
|
// were returned a pointer...
|
||||||
|
// Also couldn't find an easy way to disable the gnu version without
|
||||||
|
// changing the cxxflags globally, so forget it.
|
||||||
|
// At worse we get no message at all here.
|
||||||
errbuf[0] = 0;
|
errbuf[0] = 0;
|
||||||
strerror_r(_errno, errbuf, ERRBUFSZ);
|
strerror_r(_errno, errbuf, ERRBUFSZ);
|
||||||
reason->append(errbuf);
|
reason->append(errbuf);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user