mdbx: use FormatMessage() for Windows.

This commit is contained in:
Leo Yuriev 2017-04-25 19:17:57 +03:00
parent f91218bda4
commit 326dea8bc1
2 changed files with 11 additions and 9 deletions

View File

@ -1,4 +1,4 @@
- [ ] разделение errno и GetLastError() - [x] разделение errno и GetLastError()
- [x] CI посредством AppVeyor - [x] CI посредством AppVeyor
- [ ] uint32/uint64 в структурах - [ ] uint32/uint64 в структурах
- [ ] правки API (много...) - [ ] правки API (много...)

View File

@ -763,10 +763,10 @@ const char *__cold mdbx_strerror_r(int errnum, char *buf, size_t buflen) {
if (!buflen) if (!buflen)
return NULL; return NULL;
#ifdef _MSC_VER #ifdef _MSC_VER
int rc = strerror_s(buf, buflen, errnum); size_t size = FormatMessageA(
assert(rc == 0); FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
(void)rc; errnum, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, buflen, NULL);
return buf; return size ? buf : NULL;
#elif defined(_GNU_SOURCE) #elif defined(_GNU_SOURCE)
/* GNU-specific */ /* GNU-specific */
msg = strerror_r(errnum, buf, buflen); msg = strerror_r(errnum, buf, buflen);
@ -792,10 +792,12 @@ const char *__cold mdbx_strerror(int errnum) {
if (!msg) { if (!msg) {
#ifdef _MSC_VER #ifdef _MSC_VER
static __thread char buffer[1024]; static __thread char buffer[1024];
int rc = strerror_s(buffer, sizeof(buffer), errnum); size_t size = FormatMessageA(
assert(rc == 0); FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
(void)rc; errnum, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer,
msg = buffer; sizeof(buffer), NULL);
if (size)
msg = buffer;
#else #else
msg = strerror(errnum); msg = strerror(errnum);
#endif #endif