gdbmobj2.c
上传用户:s81996212
上传日期:2007-01-04
资源大小:722k
文件大小:1k
源码类别:

WEB邮件程序

开发平台:

C/C++

  1. /*
  2. ** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
  3. ** distribution information.
  4. */
  5. #include "gdbmobj.h"
  6. static char *fetchkeyval(struct gdbmobj *obj, size_t *, char **, size_t *);
  7. extern char *gdbm_dofetch(struct gdbmobj *, const char *, size_t, size_t *);
  8. char *gdbmobj_firstkey(struct gdbmobj *obj, size_t *keylen, char **val,
  9. size_t *vallen)
  10. {
  11. datum key;
  12. if (!obj->has_dbf) return (0);
  13. if (obj->prev_key) free(obj->prev_key);
  14. obj->prev_key=0;
  15. key=gdbm_firstkey(obj->dbf);
  16. if (!key.dptr) return (0);
  17. obj->prev_key=key.dptr;
  18. obj->prev_key_len=key.dsize;
  19. return (fetchkeyval(obj, keylen, val, vallen));
  20. }
  21. static char *fetchkeyval(struct gdbmobj *obj, size_t *keylen, char **val,
  22. size_t *vallen)
  23. {
  24. if (!obj->prev_key) return (0);
  25. *val=gdbm_dofetch(obj, obj->prev_key, obj->prev_key_len, vallen);
  26. *keylen=obj->prev_key_len;
  27. return (obj->prev_key);
  28. }
  29. char *gdbmobj_nextkey(struct gdbmobj *obj, size_t *keylen,
  30. char **val, size_t *vallen)
  31. {
  32. datum dkey, key;
  33. if (!obj->has_dbf || !obj->prev_key) return (0);
  34. dkey.dptr=(char *)obj->prev_key;
  35. dkey.dsize=obj->prev_key_len;
  36. key=gdbm_nextkey(obj->dbf, dkey);
  37. free(obj->prev_key);
  38. obj->prev_key=key.dptr;
  39. obj->prev_key_len=key.dsize;
  40. return (fetchkeyval(obj, keylen, val, vallen));
  41. }