1#![allow(dead_code, non_camel_case_types)]
2
3extern crate libc;
4
5pub use self::os::{mdb_mode_t, mdb_filehandle_t};
6use libc::{c_int, c_uint, c_void, c_char, size_t};
7
8#[cfg(any(target_os = "macos", target_os = "ios", target_os = "linux",
9 target_os = "freebsd", target_os = "dragonfly",
10 target_os = "android"))]
11mod os {
12 use libc;
13
14
15 pub type mdb_mode_t = libc::mode_t;
16
17 pub type mdb_filehandle_t = libc::c_int;
18}
19
20#[cfg(target_os = "windows")]
21mod os {
22 use libc;
23
24 pub type mdb_mode_t = libc::c_int;
25
26 pub type mdb_filehandle_t = libc::c_int;
27}
28
29pub type MDB_dbi = c_uint;
30
31pub type MDB_rel_func = extern fn(*const MDB_val, *const c_void, *const c_void, *const c_void);
32pub type MDB_msg_func = extern fn(*const c_char, *const c_void) -> c_int;
33pub type MDB_cmp_func = extern fn(*const MDB_val, *const MDB_val) -> c_int;
34
35#[derive(Copy, Clone)]
36#[repr(C)]
37pub struct MDB_val {
38 pub mv_size: size_t,
39 pub mv_data: *const c_void,
40}
41
42#[allow(missing_copy_implementations)]
43pub enum MDB_env {}
44
45#[allow(missing_copy_implementations)]
46pub enum MDB_txn {}
47
48#[allow(missing_copy_implementations)]
49pub enum MDB_cursor {}
50
51#[repr(C)]
52#[derive(Copy, Clone)]
53pub struct MDB_stat {
54 pub ms_psize: c_uint,
55 pub ms_depth: c_uint,
56 pub ms_branch_pages: size_t,
57 pub ms_leaf_pages: size_t,
58 pub ms_overflow_pages: size_t,
59 pub ms_entries: size_t
60}
61
62#[repr(C)]
63#[allow(missing_copy_implementations)]
64pub struct MDB_envinfo {
65 pub me_mapaddr: *const c_void,
66 pub me_mapsize: size_t,
67 pub me_last_pgno: size_t,
68 pub me_last_txnid: size_t,
69 pub me_maxreaders: c_uint,
70 pub me_numreaders: c_uint
71}
72
73#[repr(C)]
74#[derive(Copy, Clone, Eq, PartialEq)]
75pub enum MDB_cursor_op {
76 MDB_FIRST,
77 MDB_FIRST_DUP,
78 MDB_GET_BOTH,
79 MDB_GET_BOTH_RANGE,
80 MDB_GET_CURRENT,
81 MDB_GET_MULTIPLE,
82 MDB_LAST,
83 MDB_LAST_DUP,
84 MDB_NEXT,
85 MDB_NEXT_DUP,
86 MDB_NEXT_MULTIPLE,
87 MDB_NEXT_NODUP,
88 MDB_PREV,
89 MDB_PREV_DUP,
90 MDB_PREV_NODUP,
91 MDB_SET,
92 MDB_SET_KEY,
93 MDB_SET_RANGE
94}
95
96pub const MDB_SUCCESS: c_int = 0;
98pub const MDB_KEYEXIST: c_int = -30799;
99pub const MDB_NOTFOUND: c_int = -30798;
100pub const MDB_PAGE_NOTFOUND: c_int = -30797;
101pub const MDB_CORRUPTED: c_int = -30796;
102pub const MDB_PANIC: c_int = -30795;
103pub const MDB_VERSION_MISMATCH: c_int = -30794;
104pub const MDB_INVALID: c_int = -30793;
105pub const MDB_MAP_FULL: c_int = -30792;
106pub const MDB_DBS_FULL: c_int = -30791;
107pub const MDB_READERS_FULL: c_int = -30790;
108pub const MDB_TLS_FULL: c_int = -30789;
109pub const MDB_TXN_FULL: c_int = -30788;
110pub const MDB_CURSOR_FULL: c_int = -30787;
111pub const MDB_PAGE_FULL: c_int = -30786;
112pub const MDB_MAP_RESIZED: c_int = -30785;
113pub const MDB_INCOMPATIBLE: c_int = -30784;
114pub const MDB_BAD_RSLOT: c_int = -30783;
115pub const MDB_BAD_TXN: c_int = -30782;
116pub const MDB_BAD_VALSIZE: c_int = -30781;
117
118pub const MDB_NOOVERWRITE: c_uint = 0x10;
120pub const MDB_NODUPDATA: c_uint = 0x20;
121pub const MDB_CURRENT: c_uint = 0x40;
122pub const MDB_RESERVE: c_uint = 0x10000;
123pub const MDB_APPEND: c_uint = 0x20000;
124pub const MDB_APPENDDUP: c_uint = 0x40000;
125pub const MDB_MULTIPLE: c_uint = 0x80000;
126
127pub const MDB_REVERSEKEY: c_uint = 0x02;
129pub const MDB_DUPSORT: c_uint = 0x04;
130pub const MDB_INTEGERKEY: c_uint = 0x08;
131pub const MDB_DUPFIXED: c_uint = 0x10;
132pub const MDB_INTEGERDUP: c_uint = 0x20;
133pub const MDB_REVERSEDUP: c_uint = 0x40;
134pub const MDB_CREATE: c_uint = 0x40000;
135
136pub const MDB_FIXEDMAP: c_uint = 0x01;
138pub const MDB_NOSUBDIR: c_uint = 0x4000;
139pub const MDB_NOSYNC: c_uint = 0x10000;
140pub const MDB_RDONLY: c_uint = 0x20000;
141pub const MDB_NOMETASYNC: c_uint = 0x40000;
142pub const MDB_WRITEMAP: c_uint = 0x80000;
143pub const MDB_MAPASYNC: c_uint = 0x100000;
144pub const MDB_NOTLS: c_uint = 0x200000;
145pub const MDB_NOLOCK: c_uint = 0x400000;
146pub const MDB_NORDAHEAD: c_uint = 0x800000;
147pub const MDB_NOMEMINIT: c_uint = 0x1000000;
148
149extern "C" {
151 pub fn mdb_version(major: *mut c_int, minor: *mut c_int, patch: *mut c_int) -> *const c_char;
152 pub fn mdb_strerror(err: c_int) -> *const c_char;
153 pub fn mdb_env_create(env: *mut *mut MDB_env) -> c_int;
154 pub fn mdb_env_open(env: *mut MDB_env, path: *const c_char, flags: c_uint, mode: mdb_mode_t) -> c_int;
155 pub fn mdb_env_copy(env: *mut MDB_env, path: *const c_char) -> c_int;
156 pub fn mdb_env_copyfd(env: *mut MDB_env, fd: mdb_filehandle_t) -> c_int;
157 pub fn mdb_env_stat(env: *mut MDB_env, stat: *mut MDB_stat) -> c_int;
158 pub fn mdb_env_info(env: *mut MDB_env, info: *mut MDB_envinfo) -> c_int;
159 pub fn mdb_env_sync(env: *mut MDB_env, force: c_int) -> c_int;
160 pub fn mdb_env_close(env: *mut MDB_env);
161 pub fn mdb_env_set_flags(env: *mut MDB_env, flags: c_uint, onoff: c_int) -> c_int;
162 pub fn mdb_env_get_flags(env: *mut MDB_env, flags: *mut c_uint) -> c_int;
163 pub fn mdb_env_get_path(env: *mut MDB_env, path: *mut *mut c_char) -> c_int;
164 pub fn mdb_env_get_fd(env: *mut MDB_env, fd: *mut mdb_filehandle_t) -> c_int;
165 pub fn mdb_env_set_mapsize(env: *mut MDB_env, size: size_t) -> c_int;
166 pub fn mdb_env_set_maxreaders(env: *mut MDB_env, readers: c_uint) -> c_int;
167 pub fn mdb_env_get_maxreaders(env: *mut MDB_env, readers: *mut c_uint) -> c_int;
168 pub fn mdb_env_set_maxdbs(env: *mut MDB_env, dbs: MDB_dbi) -> c_int;
169 pub fn mdb_env_get_maxkeysize(env: *mut MDB_env) -> c_int;
170 pub fn mdb_txn_begin(env: *mut MDB_env, parent: *mut MDB_txn, flags: c_uint, txn: *mut *mut MDB_txn) -> c_int;
171 pub fn mdb_txn_env(txn: *mut MDB_txn) -> *mut MDB_env;
172 pub fn mdb_txn_commit(txn: *mut MDB_txn) -> c_int;
173 pub fn mdb_txn_abort(txn: *mut MDB_txn);
174 pub fn mdb_txn_reset(txn: *mut MDB_txn);
175 pub fn mdb_txn_renew(txn: *mut MDB_txn) -> c_int;
176 pub fn mdb_dbi_open(txn: *mut MDB_txn, name: *const c_char, flags: c_uint, dbi: *mut MDB_dbi) -> c_int;
177 pub fn mdb_stat(txn: *mut MDB_txn, dbi: MDB_dbi, stat: *mut MDB_stat) -> c_int;
178 pub fn mdb_dbi_flags(txn: *mut MDB_txn, dbi: MDB_dbi, flags: *mut c_uint) -> c_int;
179 pub fn mdb_dbi_close(txn: *mut MDB_env, dbi: MDB_dbi);
180 pub fn mdb_drop(txn: *mut MDB_txn, dbi: MDB_dbi, del: c_int) -> c_int;
181 pub fn mdb_set_compare(txn: *mut MDB_txn, dbi: MDB_dbi, cmp: MDB_cmp_func) -> c_int;
182 pub fn mdb_set_dupsort(txn: *mut MDB_txn, dbi: MDB_dbi, cmp: MDB_cmp_func) -> c_int;
183 pub fn mdb_set_relfunc(txn: *mut MDB_txn, dbi: MDB_dbi, rel: MDB_rel_func) -> c_int;
184 pub fn mdb_set_relctx(txn: *mut MDB_txn, dbi: MDB_dbi, ctx: *const c_void) -> c_int;
185 pub fn mdb_get(txn: *mut MDB_txn, dbi: MDB_dbi, key: *mut MDB_val, data: *mut MDB_val) -> c_int;
186 pub fn mdb_put(txn: *mut MDB_txn, dbi: MDB_dbi, key: *mut MDB_val, data: *mut MDB_val, flags: c_uint) -> c_int;
187 pub fn mdb_del(txn: *mut MDB_txn, dbi: MDB_dbi, key: *mut MDB_val, data: *mut MDB_val) -> c_int;
188 pub fn mdb_cursor_open(txn: *mut MDB_txn, dbi: MDB_dbi, cursor: *mut *mut MDB_cursor) -> c_int;
189 pub fn mdb_cursor_close(cursor: *mut MDB_cursor) -> c_int;
190 pub fn mdb_cursor_renew(txn: *mut MDB_txn, cursor: *mut MDB_cursor) -> c_int;
191 pub fn mdb_cursor_txn(cursor: *mut MDB_cursor) -> *mut MDB_txn;
192 pub fn mdb_cursor_dbi(cursor: *mut MDB_cursor) -> *mut MDB_dbi;
193 pub fn mdb_cursor_get(cursor: *mut MDB_cursor, key: *mut MDB_val, data: *mut MDB_val, op: MDB_cursor_op) -> c_int;
194 pub fn mdb_cursor_put(cursor: *mut MDB_cursor, key: *mut MDB_val, data: *mut MDB_val, flags: c_uint) -> c_int;
195 pub fn mdb_cursor_del(cursor: *mut MDB_cursor, flags: c_uint) -> c_int;
196 pub fn mdb_cursor_count(cursor: *mut MDB_cursor, countp: *mut size_t) -> c_int;
197 pub fn mdb_cmp(txn: *mut MDB_txn, dbi: MDB_dbi, a: *mut MDB_val, b: *mut MDB_val) -> c_int;
198 pub fn mdb_dcmp(txn: *mut MDB_txn, dbi: MDB_dbi, a: *mut MDB_val, b: *mut MDB_val) -> c_int;
199 pub fn mdb_reader_list(env: *mut MDB_env, func: MDB_msg_func, ctx: *const c_void) -> c_int;
200 pub fn mdb_reader_check(env: *mut MDB_env, dead: *mut c_int) -> c_int;
201}
202
203impl std::fmt::Debug for MDB_val {
204 fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
205 unsafe {
206 let buf: &[u8] = std::slice::from_raw_parts(std::mem::transmute(self.mv_data),
207 self.mv_size as usize);
208 write!(fmt, "{:?}@{:?}", buf, self.mv_data)
209 }
210 }
211}