Back to index

courier  0.68.2
gdbmobj2.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
00003 ** distribution information.
00004 */
00005 
00006 #include      "gdbmobj.h"
00007 
00008 static char *fetchkeyval(struct gdbmobj *obj, size_t *, char **, size_t *);
00009 extern char *gdbm_dofetch(struct gdbmobj *, const char *, size_t, size_t *);
00010 
00011 char   *gdbmobj_firstkey(struct gdbmobj *obj, size_t *keylen, char **val,
00012        size_t *vallen)
00013 {
00014 datum  key;
00015 
00016        if (!obj->has_dbf)   return (0);
00017 
00018        if (obj->prev_key)   free(obj->prev_key);
00019        obj->prev_key=0;
00020 
00021        key=gdbm_firstkey(obj->dbf);
00022 
00023        if (!key.dptr)       return (0);
00024 
00025        obj->prev_key=key.dptr;
00026        obj->prev_key_len=key.dsize;
00027        return (fetchkeyval(obj, keylen, val, vallen));
00028 }
00029 
00030 
00031 static char *fetchkeyval(struct gdbmobj *obj, size_t *keylen, char **val,
00032        size_t *vallen)
00033 {
00034        if (!obj->prev_key)  return (0);
00035        *val=gdbm_dofetch(obj, obj->prev_key, obj->prev_key_len, vallen);
00036        *keylen=obj->prev_key_len;
00037        return (obj->prev_key);
00038 }
00039 
00040 char   *gdbmobj_nextkey(struct gdbmobj *obj, size_t *keylen,
00041        char **val, size_t *vallen)
00042 {
00043 datum  dkey, key;
00044 
00045        if (!obj->has_dbf || !obj->prev_key)      return (0);
00046 
00047        dkey.dptr=(char *)obj->prev_key;
00048        dkey.dsize=obj->prev_key_len;
00049 
00050        key=gdbm_nextkey(obj->dbf, dkey);
00051 
00052        free(obj->prev_key);
00053        obj->prev_key=key.dptr;
00054        obj->prev_key_len=key.dsize;
00055        return (fetchkeyval(obj, keylen, val, vallen));
00056 }