Compare commits

..

1 Commits

Author SHA1 Message Date
6cfacd05d8
Fix for broken strerr_r definition in alpine 2021-12-21 10:04:08 +00:00
2 changed files with 21 additions and 9 deletions

View File

@ -80,17 +80,26 @@ std::string logger::format(const std::string& fmt, ...)
return buf;
}
// alpine has a broken definition for strerr_r
// see https://stackoverflow.com/questions/41953104/strerror-r-is-incorrectly-declared-on-alpine-linux
std::string logger::err_str(int result, char *buff, int err)
{
if (result)
sprintf(buff, "unknown error: %d", err);
return buff;
}
std::string logger::err_str(char *result, char *buff, int err)
{
return result;
}
std::string logger::err()
{
char buf[2048];
#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
if (strerror_r(errno, buf, sizeof(buf))
return "Unknown error";
return buf;
#else
return strerror_r(errno, buf, sizeof(buf));
#endif
return logger::err_str(strerror_r(errno, buf, sizeof(buf)), buf, errno);
}
logger logger::error()

View File

@ -74,6 +74,7 @@ public:
static std::string err();
private:
int _pri;
std::stringstream _ss;
@ -91,7 +92,9 @@ private:
static int _max_pri;
// fixes for strerr_r on alpine
static std::string err_str(int result, char *buff, int err);
static std::string err_str(char *result, char *buff, int err);
};
NDPPD_NS_END