1 /* We should be able to tdb_check a O_RDONLY tdb, and we were previously allowed
2 * to tdb_check() inside a transaction (though that's paranoia!). */
3 #define _XOPEN_SOURCE 500
4 #include "../common/tdb_private.h"
5 #include "../common/io.c"
6 #include "../common/tdb.c"
7 #include "../common/lock.c"
8 #include "../common/freelist.c"
9 #include "../common/traverse.c"
10 #include "../common/transaction.c"
11 #include "../common/error.c"
12 #include "../common/open.c"
13 #include "../common/check.c"
14 #include "../common/hash.c"
15 #include <ccan/tap/tap.h>
20 int main(int argc, char *argv[])
22 struct tdb_context *tdb;
26 tdb = tdb_open_ex("run-readonly-check.tdb", 1024,
28 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
31 key.dsize = strlen("hi");
32 key.dptr = (void *)"hi";
33 data.dsize = strlen("world");
34 data.dptr = (void *)"world";
36 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
37 ok1(tdb_check(tdb, NULL, NULL) == 0);
39 /* We are also allowed to do a check inside a transaction. */
40 ok1(tdb_transaction_start(tdb) == 0);
41 ok1(tdb_check(tdb, NULL, NULL) == 0);
42 ok1(tdb_close(tdb) == 0);
44 tdb = tdb_open_ex("run-readonly-check.tdb", 1024,
45 TDB_DEFAULT, O_RDONLY, 0, &taplogctx, NULL);
48 ok1(tdb_store(tdb, key, data, TDB_MODIFY) == -1);
49 ok1(tdb_error(tdb) == TDB_ERR_RDONLY);
50 ok1(tdb_check(tdb, NULL, NULL) == 0);
51 ok1(tdb_close(tdb) == 0);