]> git.ozlabs.org Git - ccan/blob - ccan/tdb/test/run-zero-append.c
Fix bug where we used old clear_if_first when doing I/O in open.
[ccan] / ccan / tdb / test / run-zero-append.c
1 #define _XOPEN_SOURCE 500
2 #include <ccan/tdb/tdb.h>
3 #include <ccan/tdb/io.c>
4 #include <ccan/tdb/tdb.c>
5 #include <ccan/tdb/lock.c>
6 #include <ccan/tdb/freelist.c>
7 #include <ccan/tdb/traverse.c>
8 #include <ccan/tdb/transaction.c>
9 #include <ccan/tdb/error.c>
10 #include <ccan/tdb/open.c>
11 #include <ccan/tap/tap.h>
12 #include <stdlib.h>
13 #include <err.h>
14
15 int main(int argc, char *argv[])
16 {
17         struct tdb_context *tdb;
18         TDB_DATA key, data;
19
20         plan_tests(4);
21         tdb = tdb_open(NULL, 1024, TDB_INTERNAL, O_CREAT|O_TRUNC|O_RDWR, 0600);
22         ok1(tdb);
23
24         /* Tickle bug on appending zero length buffer to zero length buffer. */
25         key.dsize = strlen("hi");
26         key.dptr = (void *)"hi";
27         data.dptr = (void *)"world";
28         data.dsize = 0;
29
30         ok1(tdb_append(tdb, key, data) == 0);
31         ok1(tdb_append(tdb, key, data) == 0);
32         data = tdb_fetch(tdb, key);
33         ok1(data.dsize == 0);
34         tdb_close(tdb);
35
36         return exit_status();
37 }