mdbx-windows: add mdbx_strerror_ANSI2OEM() and mdbx_strerror_r_ANSI2OEM().

This commit is contained in:
Leonid Yuriev 2019-08-28 17:12:32 +03:00
parent 10ab5dc032
commit 368b48b41b
2 changed files with 29 additions and 2 deletions

7
mdbx.h
View File

@ -526,6 +526,13 @@ typedef struct MDBX_envinfo {
LIBMDBX_API const char *mdbx_strerror(int errnum);
LIBMDBX_API const char *mdbx_strerror_r(int errnum, char *buf, size_t buflen);
#if defined(_WIN32) || defined(_WIN64)
/* Bit of madness for Windows */
LIBMDBX_API const char *mdbx_strerror_ANSI2OEM(int errnum);
LIBMDBX_API const char *mdbx_strerror_r_ANSI2OEM(int errnum, char *buf,
size_t buflen);
#endif /* Bit of madness for Windows */
/* Create an MDBX environment handle.
*
* This function allocates memory for a MDBX_env structure. To release

View File

@ -1335,7 +1335,7 @@ const char *__cold mdbx_strerror_r(int errnum, char *buf, size_t buflen) {
const char *msg = __mdbx_strerr(errnum);
if (!msg && buflen > 0 && buflen < INT_MAX) {
#if defined(_WIN32) || defined(_WIN64)
const size_t size = FormatMessageA(
const DWORD size = FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
errnum, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (DWORD)buflen,
NULL);
@ -1366,7 +1366,7 @@ const char *__cold mdbx_strerror_r(int errnum, char *buf, size_t buflen) {
const char *__cold mdbx_strerror(int errnum) {
#if defined(_WIN32) || defined(_WIN64)
static char buf[1024];
return mdbx_strerror_r(errnu, buf, sizeof(buf));
return mdbx_strerror_r(errnum, buf, sizeof(buf));
#else
const char *msg = __mdbx_strerr(errnum);
if (!msg) {
@ -1381,6 +1381,26 @@ const char *__cold mdbx_strerror(int errnum) {
#endif
}
#if defined(_WIN32) || defined(_WIN64) /* Bit of madness for Windows */
const char *mdbx_strerror_r_ANSI2OEM(int errnum, char *buf, size_t buflen) {
const char *msg = __mdbx_strerr(errnum);
if (!msg && buflen > 0 && buflen < INT_MAX) {
const DWORD size = FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
errnum, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (DWORD)buflen,
NULL);
if (size && CharToOemBuffA(buf, buf, size))
msg = buf;
}
return msg;
}
const char *mdbx_strerror_ANSI2OEM(int errnum) {
static char buf[1024];
return mdbx_strerror_r_ANSI2OEM(errnum, buf, sizeof(buf));
}
#endif /* Bit of madness for Windows */
static txnid_t mdbx_oomkick(MDBX_env *env, const txnid_t laggard);
void __cold mdbx_debug_log(int type, const char *function, int line,