1 #define _XOPEN_SOURCE 500
2 #include "../common/tdb_private.h"
3 #include "../common/io.c"
4 #include "../common/tdb.c"
5 #include "../common/lock.c"
6 #include "../common/freelist.c"
7 #include "../common/traverse.c"
8 #include "../common/transaction.c"
9 #include "../common/error.c"
10 #include "../common/open.c"
11 #include "../common/check.c"
12 #include "../common/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);