Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
902 B

16 years ago
16 years ago
16 years ago
16 years ago
  1. #include "cdb.h"
  2. static int doit(struct cdb *c,uint32 *kpos) {
  3. unsigned char buf[8];
  4. uint32 eod,klen;
  5. if (cdb_read(c,buf,4,0)) return -1;
  6. uint32_unpack((char*)buf,&eod);
  7. if (eod<8 || eod-8<*kpos) return 0;
  8. c->kpos=*kpos+8;
  9. if (c->kpos<*kpos) return -1; /* wraparound */
  10. cdb_findstart(c);
  11. c->hslots=1;
  12. if (cdb_read(c,buf,8,*kpos) == -1) return -1;
  13. uint32_unpack((char*)buf,&klen);
  14. uint32_unpack((char*)buf+4,&c->dlen);
  15. c->dpos=c->kpos+klen;
  16. *kpos+=8+klen+c->dlen;
  17. return 1;
  18. }
  19. int cdb_firstkey(struct cdb *c,uint32 *kpos) {
  20. *kpos=2048;
  21. return doit(c,kpos);
  22. }
  23. int cdb_nextkey(struct cdb *c,uint32 *kpos) {
  24. return doit(c,kpos);
  25. }
  26. int cdb_successor(struct cdb *c,const unsigned char *key,size_t klen) {
  27. int r;
  28. uint32 kpos;
  29. if (key) {
  30. r=cdb_find(c,key,klen);
  31. if (r<1) return r;
  32. kpos=c->dpos+c->dlen;
  33. } else
  34. kpos=2048;
  35. return doit(c,&kpos);
  36. }