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>
15 int main(int argc, char *argv[])
17 struct tdb_context *tdb;
18 struct tdb_header hdr;
22 /* Can open fine if complete crap, as long as O_CREAT. */
23 fd = open("/tmp/test.tdb", O_RDWR|O_CREAT|O_TRUNC, 0600);
25 ok1(write(fd, "hello world", 11) == 11);
27 tdb = tdb_open("/tmp/test.tdb", 1024, 0, O_RDWR, 0);
29 tdb = tdb_open("/tmp/test.tdb", 1024, 0, O_CREAT|O_RDWR, 0600);
33 /* Now, with wrong version it should *not* overwrite. */
34 fd = open("/tmp/test.tdb", O_RDWR);
36 ok1(read(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
37 ok1(hdr.version == TDB_VERSION);
39 lseek(fd, 0, SEEK_SET);
40 ok1(write(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
43 tdb = tdb_open("/tmp/test.tdb", 1024, 0, O_RDWR|O_CREAT, 0600);
47 /* With truncate, will be fine. */
48 tdb = tdb_open("/tmp/test.tdb", 1024, 0, O_RDWR|O_CREAT|O_TRUNC, 0600);
51 unlink("/tmp/test.tdb");