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/tdb/hash.c>
13 #include <ccan/tap/tap.h>
18 int main(int argc, char *argv[])
20 struct tdb_context *tdb;
21 struct tdb_header hdr;
25 /* Can open fine if complete crap, as long as O_CREAT. */
26 fd = open("run-bad-tdb-header.tdb", O_RDWR|O_CREAT|O_TRUNC, 0600);
28 ok1(write(fd, "hello world", 11) == 11);
30 tdb = tdb_open_ex("run-bad-tdb-header.tdb", 1024, 0, O_RDWR, 0,
33 tdb = tdb_open_ex("run-bad-tdb-header.tdb", 1024, 0, O_CREAT|O_RDWR,
34 0600, &taplogctx, NULL);
38 /* Now, with wrong version it should *not* overwrite. */
39 fd = open("run-bad-tdb-header.tdb", O_RDWR);
41 ok1(read(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
42 ok1(hdr.version == TDB_VERSION);
44 lseek(fd, 0, SEEK_SET);
45 ok1(write(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
48 tdb = tdb_open_ex("run-bad-tdb-header.tdb", 1024, 0, O_RDWR|O_CREAT,
49 0600, &taplogctx, NULL);
53 /* With truncate, will be fine. */
54 tdb = tdb_open_ex("run-bad-tdb-header.tdb", 1024, 0,
55 O_RDWR|O_CREAT|O_TRUNC, 0600, &taplogctx, NULL);