1#![allow(non_camel_case_types)]
2#![allow(dead_code)]
3
4extern crate libc;
5
6use libc::{c_int, c_uchar, c_uint, c_void};
7
8#[repr(C)]
9pub struct cdb {
10 pub cdb_fd: c_int,
12
13 cdb_fsize: c_uint,
15
16 cdb_dend: c_uint,
18
19 cdb_mem: *const c_uchar,
21
22 cdb_vpos: c_uint,
24 cdb_vlen: c_uint,
25
26 cdb_kpos: c_uint,
28 cdb_klen: c_uint,
29}
30
31impl cdb {
33 #[inline]
34 pub fn cdb_datapos(&self) -> c_uint {
35 self.cdb_vpos
36 }
37
38 #[inline]
39 pub fn cdb_datalen(&self) -> c_uint {
40 self.cdb_vlen
41 }
42
43 #[inline]
44 pub fn cdb_keypos(&self) -> c_uint {
45 self.cdb_kpos
46 }
47
48 #[inline]
49 pub fn cdb_keylen(&self) -> c_uint {
50 self.cdb_klen
51 }
52}
53
54#[repr(C)]
55pub struct cdb_find {
56 cdb_cdbp: *mut cdb,
57 cdb_hval: c_uint,
58 cdb_htp: *const c_uchar,
59 cdb_htab: *const c_uchar,
60 cdb_htend: *const c_uchar,
61 cdb_httodo: c_uint,
62 cdb_key: *const c_void,
63 cdb_klen: c_uint,
64}
65
66#[repr(C)]
67pub struct cdb_make {
68 pub cdb_fd: c_int,
70
71 cdb_dpos: c_uint,
73
74 cdb_rcnt: c_uint,
76
77 cdb_buf: [c_uchar; 4096],
79
80 cdb_bpos: *mut c_uchar,
82
83 cdb_rec: [*mut c_void; 256],
86}
87
88#[repr(C)]
93#[derive(Clone, Copy, Debug, PartialEq, Eq)]
94pub enum CdbPutMode {
95 Add = 0,
100
101 Replace = 1,
107
108 Insert = 2,
115
116 Warn = 3,
123
124 Replace0 = 4,
130}
131
132#[repr(C)]
133pub enum CdbFindMode {
134 Find = 0, Remove = 1, Fill0 = 4, }
138
139extern "C" {
140 pub fn cdb_init(cdbp: *mut cdb, fd: c_int) -> c_int;
141 pub fn cdb_free(cdbp: *mut cdb);
142 pub fn cdb_read(cdbp: *const cdb, buf: *mut c_void, len: c_uint, pos: c_uint) -> c_int;
143 pub fn cdb_get(cdbp: *const cdb, len: c_uint, pos: c_uint) -> *const c_void;
144
145 pub fn cdb_find(cdbp: *mut cdb, key: *const c_void, klen: c_uint) -> c_int;
146 pub fn cdb_findinit(cdbfp: *mut cdb_find, cdb: *mut cdb, key: *const c_void, klen: c_uint) -> c_int;
147 pub fn cdb_findnext(cdbfp: *mut cdb_find) -> c_int;
148
149 pub fn cdb_make_start(cdbmp: *mut cdb_make, fd: c_int) -> c_int;
150 pub fn cdb_make_add(cdbmp: *mut cdb_make, key: *const c_void, klen: c_uint, val: *const c_void, vlen: c_uint) -> c_int;
151 pub fn cdb_make_exists(cdbmp: *mut cdb_make, key: *const c_void, klen: c_uint) -> c_int;
152 pub fn cdb_make_find(cdbmp: *mut cdb_make, key: *const c_void, klen: c_uint, mode: CdbFindMode) -> c_int;
153 pub fn cdb_make_put(cdbmp: *mut cdb_make, key: *const c_void, klen: c_uint, val: *const c_void, vlen: c_uint, mode: CdbPutMode) -> c_int;
154 pub fn cdb_make_finish(cdbmp: *mut cdb_make) -> c_int;
155
156 pub fn cdb_seqnext(cptr: *mut c_uint, cdbp: *mut cdb) -> c_int;
157}
158
159pub unsafe fn cdb_seqinit(cptr: *mut c_uint, _cdbp: *mut cdb) {
161 *cptr = 2048;
162}