mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-06 22:24:13 +08:00
mdbx: add mdbx_strerror_r().
This commit is contained in:
parent
8fb2523276
commit
57dc59ecfb
37
mdbx.c
37
mdbx.c
@ -1328,7 +1328,7 @@ static pthread_mutex_t tsan_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Return the library version info. */
|
/** Return the library version info. */
|
||||||
char *__cold mdbx_version(int *major, int *minor, int *patch) {
|
const char *mdbx_version(int *major, int *minor, int *patch) {
|
||||||
if (major)
|
if (major)
|
||||||
*major = MDB_VERSION_MAJOR;
|
*major = MDB_VERSION_MAJOR;
|
||||||
if (minor)
|
if (minor)
|
||||||
@ -1338,8 +1338,9 @@ char *__cold mdbx_version(int *major, int *minor, int *patch) {
|
|||||||
return MDB_VERSION_STRING;
|
return MDB_VERSION_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Table of descriptions for LMDB @ref errors */
|
static const char *__mdbx_strerr(int err) {
|
||||||
static char *const mdbx_errstr[] = {
|
/* Table of descriptions for LMDB errors */
|
||||||
|
static const char *const tbl[] = {
|
||||||
"MDB_KEYEXIST: Key/data pair already exists",
|
"MDB_KEYEXIST: Key/data pair already exists",
|
||||||
"MDB_NOTFOUND: No matching key/data pair found",
|
"MDB_NOTFOUND: No matching key/data pair found",
|
||||||
"MDB_PAGE_NOTFOUND: Requested page not found",
|
"MDB_PAGE_NOTFOUND: Requested page not found",
|
||||||
@ -1366,17 +1367,31 @@ static char *const mdbx_errstr[] = {
|
|||||||
"MDB_PROBLEM: Unexpected problem - txn should abort",
|
"MDB_PROBLEM: Unexpected problem - txn should abort",
|
||||||
};
|
};
|
||||||
|
|
||||||
char *__cold mdbx_strerror(int err) {
|
|
||||||
int i;
|
|
||||||
if (!err)
|
|
||||||
return ("Successful return: 0");
|
|
||||||
|
|
||||||
if (err >= MDB_KEYEXIST && err <= MDB_LAST_ERRCODE) {
|
if (err >= MDB_KEYEXIST && err <= MDB_LAST_ERRCODE) {
|
||||||
i = err - MDB_KEYEXIST;
|
int i = err - MDB_KEYEXIST;
|
||||||
return mdbx_errstr[i];
|
return tbl[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return strerror(err);
|
switch (err) {
|
||||||
|
case MDB_SUCCESS:
|
||||||
|
return "Successful return: 0";
|
||||||
|
case MDBX_EMULTIVAL:
|
||||||
|
return "";
|
||||||
|
case MDBX_EBADSIGN:
|
||||||
|
return "";
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *mdbx_strerror_r(int err, char *buf, size_t buflen) {
|
||||||
|
const char *msg = __mdbx_strerr(err);
|
||||||
|
return msg ? msg : strerror_r(err, buf, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *__cold mdbx_strerror(int err) {
|
||||||
|
const char *msg = __mdbx_strerr(err);
|
||||||
|
return msg ? msg : strerror(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MDBX_MODE_ENABLED
|
#if MDBX_MODE_ENABLED
|
||||||
|
5
mdbx.h
5
mdbx.h
@ -343,7 +343,7 @@ typedef struct MDBX_envinfo {
|
|||||||
* here
|
* here
|
||||||
* Returns "version string" The library version as a string
|
* Returns "version string" The library version as a string
|
||||||
*/
|
*/
|
||||||
char *mdbx_version(int *major, int *minor, int *patch);
|
const char *mdbx_version(int *major, int *minor, int *patch);
|
||||||
|
|
||||||
/* Return a string describing a given error code.
|
/* Return a string describing a given error code.
|
||||||
*
|
*
|
||||||
@ -355,7 +355,8 @@ char *mdbx_version(int *major, int *minor, int *patch);
|
|||||||
* [in] err The error code
|
* [in] err The error code
|
||||||
* Returns "error message" The description of the error
|
* Returns "error message" The description of the error
|
||||||
*/
|
*/
|
||||||
char *mdbx_strerror(int err);
|
const char *mdbx_strerror(int err);
|
||||||
|
const char *mdbx_strerror_r(int err, char *buf, size_t buflen);
|
||||||
|
|
||||||
/* Create an LMDB environment handle.
|
/* Create an LMDB environment handle.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user