1 #include "../common/tdb_private.h"
2 #include "../common/io.c"
3 #include "../common/tdb.c"
4 #include "../common/lock.c"
5 #include "../common/freelist.c"
6 #include "../common/traverse.c"
7 #include "../common/transaction.c"
8 #include "../common/error.c"
9 #include "../common/open.c"
10 #include "../common/check.c"
11 #include "../common/hash.c"
12 #include "../common/mutex.c"
13 #include "tap-interface.h"
17 static char keystr0
[] = "x";
18 static TDB_DATA key0
= { .dptr
= (uint8_t *)keystr0
,
19 .dsize
= sizeof(keystr0
) };
20 static char valuestr0
[] = "y";
21 static TDB_DATA value0
= { .dptr
= (uint8_t *)valuestr0
,
22 .dsize
= sizeof(valuestr0
) };
24 static char keystr1
[] = "aaa";
25 static TDB_DATA key1
= { .dptr
= (uint8_t *)keystr1
,
26 .dsize
= sizeof(keystr1
) };
27 static char valuestr1
[] = "bbbbb";
28 static TDB_DATA value1
= { .dptr
= (uint8_t *)valuestr1
,
29 .dsize
= sizeof(valuestr1
) };
31 static TDB_DATA
*keys
[] = { &key0
, &key1
};
32 static TDB_DATA
*values
[] = { &value0
, &value1
};
34 static bool tdb_data_same(TDB_DATA d1
, TDB_DATA d2
)
36 if (d1
.dsize
!= d2
.dsize
) {
39 return (memcmp(d1
.dptr
, d2
.dptr
, d1
.dsize
) == 0);
42 struct traverse_chain_state
{
47 static int traverse_chain_fn(struct tdb_context
*tdb
,
52 struct traverse_chain_state
*state
= private_data
;
54 state
->ok
&= tdb_data_same(key
, *keys
[state
->idx
]);
55 state
->ok
&= tdb_data_same(data
, *values
[state
->idx
]);
61 int main(int argc
, char *argv
[])
63 struct tdb_context
*tdb
;
64 struct traverse_chain_state state
= { .ok
= true };
79 /* add in reverse order, tdb_store adds to the front of the list */
80 ret
= tdb_store(tdb
, key1
, value1
, TDB_INSERT
);
82 ret
= tdb_store(tdb
, key0
, value0
, TDB_INSERT
);
85 ret
= tdb_traverse_key_chain(tdb
, key0
, traverse_chain_fn
, &state
);
89 unlink(tdb_name(tdb
));