-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdumpdb2.cc
More file actions
45 lines (37 loc) · 953 Bytes
/
Copy pathdumpdb2.cc
File metadata and controls
45 lines (37 loc) · 953 Bytes
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
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <fcntl.h>
#include <ftw.h>
#include <string.h>
#include <leveldb/db.h>
static int nFiles;
/* leveldb_to_bdb <leveldb> <bdbfile> */
int main(int argc, char* argv[])
{
int i;
leveldb::DB* leveldb;
leveldb::Options options;
options.create_if_missing = false;
leveldb::Status status = leveldb::DB::Open(options, argv[1], &leveldb);
if (!status.ok()) {
printf("Error opening leveldb\n");
return -1;
}
leveldb::Iterator* it = leveldb->NewIterator(leveldb::ReadOptions());
for (it->SeekToFirst(); it->Valid(); it->Next()) {
char* key = strndup(it->key().data(), it->key().size());
char* value = strndup(it->value().data(), it->value().size());
printf("%s %s\n", key, value);
free(key);
free(value);
++nFiles;
}
delete it;
printf("%d files\n", nFiles);
delete leveldb;
}