forked from zhicheng/db
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb-get.c
More file actions
39 lines (30 loc) · 677 Bytes
/
Copy pathdb-get.c
File metadata and controls
39 lines (30 loc) · 677 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
#include "db.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
int
main(int argc, char *argv[])
{
db_t db;
db_option_t option;
char val[1024];
uint32_t vlen;
if (argc != 4) {
fprintf(stderr, "usage: %s [databfile] [indexfile] [key]\n", argv[0]);
return 0;
}
option.rdonly = 1;
if (db_open(&db, argv[1], argv[2], &option) != DB_OK) {
fprintf(stderr, "open db %s failed\n", argv[1]);
return 0;
}
if ((vlen = db_get(&db, argv[3], strlen(argv[3]), val, sizeof(val))) != 0) {
fwrite(val, sizeof(char), vlen, stdout);
} else {
fprintf(stderr, "NOT FOUND\n");
}
db_close(&db);
return 0;
}