1 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
21 const char data1
[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
22 const char data2
[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17};
23 const char key1
[] = {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27};
24 const char key2
[] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37};
29 struct cdbw
*cdbw
= cdbw_open();
32 int rv
= cdbw_put_data(cdbw
, data1
, __arraycount(data1
), &idx
);
35 rv
= cdbw_put_key(cdbw
, key1
, __arraycount(key1
), idx
);
38 rv
= cdbw_put(cdbw
, key2
, __arraycount(key2
), data2
, __arraycount(data2
));
41 name
= strdup("/tmp/temp.XXXXXX");
47 int fd
= open(name
, O_RDWR
| O_CREAT
, 0644);
50 cdbw_output(cdbw
, fd
, "TEST1", cdbw_stable_seeder
);
59 struct cdbr
*cdbr
= cdbr_open(name
, CDBR_DEFAULT
);
62 uint32_t idx
= cdbr_entries(cdbr
);
64 printf("entries: %" PRIu32
"\n", idx
);
68 int rv
= cdbr_get(cdbr
, idx
- 1, &data
, &data_len
);
72 for (size_t i
= 0; i
< data_len
; i
++)
73 printf("%02" PRIx8
, ((uint8_t *)data
)[i
]);
76 rv
= cdbr_find(cdbr
, key1
, __arraycount(key1
), &data
, &data_len
);
79 for (size_t i
= 0; i
< data_len
; i
++)
80 printf("%02" PRIx8
, ((uint8_t *)data
)[i
]);
86 #define COOKIE ((void *)1)
88 static void cdbr_unmap(void *cookie
, void *base
, size_t sz
) {
89 assert(cookie
== COOKIE
);
90 int rv
= munmap(base
, sz
);
97 int fd
= open(name
, O_RDONLY
);
100 int rv
= fstat(fd
, &sb
);
103 size_t sz
= sb
.st_size
;
104 assert(sz
< SSIZE_MAX
);
106 void *base
= mmap(NULL
, sz
, PROT_READ
, MAP_FILE
| MAP_SHARED
, fd
, 0);
107 assert(base
!= MAP_FAILED
);
112 struct cdbr
*cdbr
= cdbr_open_mem(base
, sz
, CDBR_DEFAULT
, cdbr_unmap
, COOKIE
);
115 printf("entries: %" PRIu32
"\n", cdbr_entries(cdbr
));
129 // CHECK: data: 1011121314151617
130 // CHECK: data: 0001020304050607