| 1 |
/* sequential record retrieval routines
|
| 2 |
*
|
| 3 |
* This file is a part of tinycdb package by Michael Tokarev, mjt@corpit.ru.
|
| 4 |
* Public domain.
|
| 5 |
*/
|
| 6 |
|
| 7 |
#include "common/setup_before.h"
|
| 8 |
#include "cdb_int.h"
|
| 9 |
#include "common/setup_after.h"
|
| 10 |
|
| 11 |
int
|
| 12 |
cdb_seqnext(unsigned *cptr, struct cdb *cdbp) {
|
| 13 |
unsigned klen, vlen;
|
| 14 |
unsigned pos = *cptr;
|
| 15 |
unsigned dend = cdbp->cdb_dend;
|
| 16 |
const unsigned char *mem = cdbp->cdb_mem;
|
| 17 |
if (pos > dend - 8)
|
| 18 |
return 0;
|
| 19 |
klen = cdb_unpack(mem + pos);
|
| 20 |
vlen = cdb_unpack(mem + pos + 4);
|
| 21 |
pos += 8;
|
| 22 |
if (dend - klen < pos || dend - vlen < pos + klen)
|
| 23 |
return errno = EPROTO, -1;
|
| 24 |
cdbp->cdb_kpos = pos;
|
| 25 |
cdbp->cdb_klen = klen;
|
| 26 |
cdbp->cdb_vpos = pos + klen;
|
| 27 |
cdbp->cdb_vlen = vlen;
|
| 28 |
*cptr = pos + klen + vlen;
|
| 29 |
return 1;
|
| 30 |
}
|