1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
5 #include "tdb1-logging.h"
7 int main(int argc, char *argv[])
9 struct tdb1_context *tdb;
10 struct tdb1_header hdr;
14 /* Can open fine if complete crap, as long as O_CREAT. */
15 fd = open("run-bad-tdb-header.tdb", O_RDWR|O_CREAT|O_TRUNC, 0600);
17 ok1(write(fd, "hello world", 11) == 11);
19 tdb = tdb1_open_ex("run-bad-tdb-header.tdb", 1024, 0, O_RDWR, 0,
22 tdb = tdb1_open_ex("run-bad-tdb-header.tdb", 1024, 0, O_CREAT|O_RDWR,
23 0600, &taplogctx, NULL);
27 /* Now, with wrong version it should *not* overwrite. */
28 fd = open("run-bad-tdb-header.tdb", O_RDWR);
30 ok1(read(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
31 ok1(hdr.version == TDB1_VERSION);
33 lseek(fd, 0, SEEK_SET);
34 ok1(write(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
37 tdb = tdb1_open_ex("run-bad-tdb-header.tdb", 1024, 0, O_RDWR|O_CREAT,
38 0600, &taplogctx, NULL);
42 /* With truncate, will be fine. */
43 tdb = tdb1_open_ex("run-bad-tdb-header.tdb", 1024, 0,
44 O_RDWR|O_CREAT|O_TRUNC, 0600, &taplogctx, NULL);