1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
7 int main(int argc, char *argv[])
9 struct tdb_context *tdb;
10 struct tdb1_header hdr;
12 union tdb_attribute hsize;
14 hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
15 hsize.base.next = &tap_log_attr;
16 hsize.tdb1_hashsize.hsize = 1024;
19 /* Cannot open fine if complete crap, even with O_CREAT. */
20 fd = open("run-bad-tdb-header.tdb1", O_RDWR|O_CREAT|O_TRUNC, 0600);
22 ok1(write(fd, "hello world", 11) == 11);
24 tdb = tdb_open("run-bad-tdb-header.tdb1", 0, O_RDWR, 0, &tap_log_attr);
26 tdb = tdb_open("run-bad-tdb-header.tdb1", 0, O_CREAT|O_RDWR,
30 /* With truncate, will be fine. */
31 tdb = tdb_open("run-bad-tdb-header.tdb1", TDB_VERSION1,
32 O_RDWR|O_CREAT|O_TRUNC, 0600, &hsize);
36 /* Now, with wrong version it should *not* overwrite. */
37 fd = open("run-bad-tdb-header.tdb1", O_RDWR);
39 ok1(read(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
40 ok1(hdr.version == TDB1_VERSION);
42 lseek(fd, 0, SEEK_SET);
43 ok1(write(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
46 tdb = tdb_open("run-bad-tdb-header.tdb1", TDB_VERSION1, O_RDWR|O_CREAT,