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/tdb/check.c>
12 #include <ccan/tap/tap.h>
16 int main(int argc, char *argv[])
18 struct tdb_context *tdb;
19 struct tdb_header hdr;
23 /* Can open fine if complete crap, as long as O_CREAT. */
24 fd = open("/tmp/test.tdb", O_RDWR|O_CREAT|O_TRUNC, 0600);
26 ok1(write(fd, "hello world", 11) == 11);
28 tdb = tdb_open("/tmp/test.tdb", 1024, 0, O_RDWR, 0);
30 tdb = tdb_open("/tmp/test.tdb", 1024, 0, O_CREAT|O_RDWR, 0600);
34 /* Now, with wrong version it should *not* overwrite. */
35 fd = open("/tmp/test.tdb", O_RDWR);
37 ok1(read(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
38 ok1(hdr.version == TDB_VERSION);
40 lseek(fd, 0, SEEK_SET);
41 ok1(write(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
44 tdb = tdb_open("/tmp/test.tdb", 1024, 0, O_RDWR|O_CREAT, 0600);
48 /* With truncate, will be fine. */
49 tdb = tdb_open("/tmp/test.tdb", 1024, 0, O_RDWR|O_CREAT|O_TRUNC, 0600);
52 unlink("/tmp/test.tdb");