mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 17:34:14 +08:00
mdbx: add mdbx_strerror_r().
This commit is contained in:
parent
8fb2523276
commit
57dc59ecfb
39
mdbx.c
39
mdbx.c
@ -1328,7 +1328,7 @@ static pthread_mutex_t tsan_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#endif
|
||||
|
||||
/** 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)
|
||||
*major = MDB_VERSION_MAJOR;
|
||||
if (minor)
|
||||
@ -1338,8 +1338,9 @@ char *__cold mdbx_version(int *major, int *minor, int *patch) {
|
||||
return MDB_VERSION_STRING;
|
||||
}
|
||||
|
||||
/** Table of descriptions for LMDB @ref errors */
|
||||
static char *const mdbx_errstr[] = {
|
||||
static const char *__mdbx_strerr(int err) {
|
||||
/* Table of descriptions for LMDB errors */
|
||||
static const char *const tbl[] = {
|
||||
"MDB_KEYEXIST: Key/data pair already exists",
|
||||
"MDB_NOTFOUND: No matching key/data pair found",
|
||||
"MDB_PAGE_NOTFOUND: Requested page not found",
|
||||
@ -1364,19 +1365,33 @@ static char *const mdbx_errstr[] = {
|
||||
"DUPFIXED size",
|
||||
"MDB_BAD_DBI: The specified DBI handle was closed/changed unexpectedly",
|
||||
"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) {
|
||||
i = err - MDB_KEYEXIST;
|
||||
return mdbx_errstr[i];
|
||||
int i = err - MDB_KEYEXIST;
|
||||
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
|
||||
|
5
mdbx.h
5
mdbx.h
@ -343,7 +343,7 @@ typedef struct MDBX_envinfo {
|
||||
* here
|
||||
* 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.
|
||||
*
|
||||
@ -355,7 +355,8 @@ char *mdbx_version(int *major, int *minor, int *patch);
|
||||
* [in] err The error code
|
||||
* 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.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user