]> git.sur5r.net Git - openldap/blob - libraries/libmdb/mfree.c
Tweak MDB restrictions
[openldap] / libraries / libmdb / mfree.c
1 /* mfree.c - memory-mapped database freelist scanner */
2 /*
3  * Copyright 2011 Howard Chu, Symas Corp.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted only as authorized by the OpenLDAP
8  * Public License.
9  *
10  * A copy of this license is available in the file LICENSE in the
11  * top-level directory of the distribution or, alternatively, at
12  * <http://www.OpenLDAP.org/license.html>.
13  */
14 #define _XOPEN_SOURCE 500               /* srandom(), random() */
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <time.h>
18 #include "mdb.h"
19 #include "midl.h"
20
21 int main(int argc,char * argv[])
22 {
23         int rc;
24         MDB_env *env;
25         MDB_dbi dbi;
26         MDB_val key, data;
27         MDB_txn *txn;
28         MDB_stat mst;
29         MDB_cursor *cursor;
30         MDB_ID i, j, *iptr;
31
32         if (argc != 2) {
33                 fprintf(stderr, "usage: %s <pathname>\n", argv[0]);
34                 exit(1);
35         }
36
37         rc = mdb_env_create(&env);
38         rc = mdb_env_open(env, argv[1], MDB_RDONLY, 0664);
39         rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
40         dbi = 0;
41         rc = mdb_cursor_open(txn, dbi, &cursor);
42         while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
43                 printf("key: %p %zu, data: %p\n",
44                         key.mv_data,  *(MDB_ID *) key.mv_data,
45                         data.mv_data);
46                 iptr = data.mv_data;
47                 j = *iptr++;
48                 for (i=0; i<j; i++)
49                         printf(" %zu\n", iptr[i]);
50         }
51         mdb_cursor_close(cursor);
52         mdb_txn_abort(txn);
53         mdb_env_close(env);
54
55         return 0;
56 }