1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/*
* $Id$
*/
#include <sys/file.h>
#include <fcntl.h>
#include <db.h>
#include <stdio.h>
main(int argc, char *argv[])
{
char *file;
DB *db;
DBT dbkey, dbdata;
int code, i;
HASHINFO info;
info.hash = NULL;
info.bsize = 256;
info.ffactor = 8;
info.nelem = 25000;
info.lorder = 0;
if (argc != 2) {
fprintf(stderr, "usage: argv[0] dbfile\n");
exit(2);
}
file = argv[1];
if((db = dbopen(file, O_RDWR, 0666, DB_HASH, &info)) == NULL) {
perror("Opening db file");
exit(1);
}
if ((code = (*db->seq)(db, &dbkey, &dbdata, R_FIRST)) == -1) {
perror("starting db iteration");
exit(1);
}
while (code == 0) {
for (i=0; i<dbkey.size; i++)
printf("%02x", (int) ((unsigned char *) dbkey.data)[i]);
printf("\t");
for (i=0; i<dbdata.size; i++)
printf("%02x", (int) ((unsigned char *) dbdata.data)[i]);
printf("\n");
code = (*db->seq)(db, &dbkey, &dbdata, R_NEXT);
}
if (code == -1) {
perror("during db iteration");
exit(1);
}
if ((*db->close)(db) == -1) {
perror("closing db");
exit(1);
}
exit(0);
}
|