#include <sys/types.h>
#include <inttypes.h>
+#include <limits.h>
#ifdef __cplusplus
extern "C" {
typedef mode_t mdb_mode_t;
#endif
-#ifdef MDB_VL32
-typedef uint64_t mdb_size_t;
-#define mdb_env_create mdb_env_create_vl32 /**< Prevent mixing with non-VL32 builds */
+#ifdef _WIN32
+# define MDB_FMT_Z "I"
#else
+# define MDB_FMT_Z "z" /**< printf/scanf format modifier for size_t */
+#endif
+
+#ifndef MDB_VL32
typedef size_t mdb_size_t;
+# define MDB_SIZE_MAX SIZE_MAX /**< max #mdb_size_t */
+/** #mdb_size_t printf formats, \b t = one of [diouxX] without quotes */
+# define MDB_PRIy(t) MDB_FMT_Z #t
+/** #mdb_size_t scanf formats, \b t = one of [dioux] without quotes */
+# define MDB_SCNy(t) MDB_FMT_Z #t
+#else
+typedef uint64_t mdb_size_t;
+# define MDB_SIZE_MAX UINT64_MAX
+# define MDB_PRIy(t) PRI##t##64
+# define MDB_SCNy(t) SCN##t##64
+# define mdb_env_create mdb_env_create_vl32 /**< Prevent mixing with non-VL32 builds */
#endif
/** An abstraction for a file handle.
#define MDB_REVERSEKEY 0x02
/** use sorted duplicates */
#define MDB_DUPSORT 0x04
- /** numeric keys in native byte order: either unsigned int or size_t.
+ /** numeric keys in native byte order, either unsigned int or #mdb_size_t.
+ * (lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)
* The keys must all be of the same size. */
#define MDB_INTEGERKEY 0x08
/** with #MDB_DUPSORT, sorted dup items have fixed size */
#define MDB_BAD_VALSIZE (-30781)
/** The specified DBI was changed unexpectedly */
#define MDB_BAD_DBI (-30780)
+ /** Unexpected problem - txn should abort */
+#define MDB_PROBLEM (-30779)
/** The last defined error code */
-#define MDB_LAST_ERRCODE MDB_BAD_DBI
+#define MDB_LAST_ERRCODE MDB_PROBLEM
/** @} */
/** @brief Statistics for a database in the environment */
* <li>#MDB_CP_COMPACT - Perform compaction while copying: omit free
* pages and sequentially renumber all pages in output. This option
* consumes more CPU and runs more slowly than the default.
+ * Currently it fails if the environment has suffered a page leak.
* </ul>
* @return A non-zero error value on failure and 0 on success.
*/
* keys must be unique and may have only a single data item.
* <li>#MDB_INTEGERKEY
* Keys are binary integers in native byte order, either unsigned int
- * or size_t, and will be sorted as such.
+ * or #mdb_size_t, and will be sorted as such.
+ * (lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)
* The keys must all be of the same size.
* <li>#MDB_DUPFIXED
* This flag may only be used in combination with #MDB_DUPSORT. This option