Rizin
unix-like reverse engineering framework and cli tools
cdb.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: D. J. Bernstein <djb@cr.yp.to>
2 // SPDX-License-Identifier: CC-PDDC
3 
4 #ifndef CDB_H
5 #define CDB_H
6 
7 #include <string.h>
8 #include <rz_types.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #define KVLSZ 4
15 #define CDB_MAX_KEY 0xff
16 #define CDB_MAX_VALUE 0xffffff
17 
18 #define CDB_HASHSTART 5381
19 
20 struct cdb {
21  char *map; /* 0 if no map is available */
22  int fd; /* filedescriptor */
23  ut32 size; /* initialized if map is nonzero */
24  ut32 loop; /* number of hash slots searched under this key */
25  ut32 khash; /* initialized if loop is nonzero */
26  ut32 kpos; /* initialized if loop is nonzero */
27  ut32 hpos; /* initialized if loop is nonzero */
28  ut32 hslots; /* initialized if loop is nonzero */
29  ut32 dpos; /* initialized if cdb_findnext() returns 1 */
30  ut32 dlen; /* initialized if cdb_findnext() returns 1 */
31 };
32 
33 /* TODO THIS MUST GTFO! */
34 bool cdb_getkvlen(struct cdb *db, ut32 *klen, ut32 *vlen, ut32 pos);
35 void cdb_free(struct cdb *);
36 bool cdb_init(struct cdb *, int fd);
37 void cdb_findstart(struct cdb *);
38 bool cdb_read(struct cdb *, char *, unsigned int, ut32);
39 int cdb_findnext(struct cdb *, ut32 u, const char *, ut32);
40 
41 #define cdb_datapos(c) ((c)->dpos)
42 #define cdb_datalen(c) ((c)->dlen)
43 
44 #ifdef __cplusplus
45 }
46 #endif
47 
48 #endif
bool cdb_getkvlen(struct cdb *db, ut32 *klen, ut32 *vlen, ut32 pos)
Definition: cdb.c:15
int cdb_findnext(struct cdb *, ut32 u, const char *, ut32)
Definition: cdb.c:132
bool cdb_init(struct cdb *, int fd)
Definition: cdb.c:51
void cdb_findstart(struct cdb *)
Definition: cdb.c:42
bool cdb_read(struct cdb *, char *, unsigned int, ut32)
Definition: cdb.c:89
void cdb_free(struct cdb *)
Definition: cdb.c:30
uint32_t ut32
Definition: cdb.h:20
ut32 hslots
Definition: cdb.h:28
char * map
Definition: cdb.h:21
ut32 size
Definition: cdb.h:23
ut32 hpos
Definition: cdb.h:27
ut32 dlen
Definition: cdb.h:30
ut32 dpos
Definition: cdb.h:29
ut32 kpos
Definition: cdb.h:26
int fd
Definition: cdb.h:22
ut32 khash
Definition: cdb.h:25
ut32 loop
Definition: cdb.h:24
int pos
Definition: main.c:11
static const z80_opcode fd[]
Definition: z80_tab.h:997