summaryrefslogtreecommitdiffstats
path: root/bdbobj/bdbobj2.c
diff options
context:
space:
mode:
authorSam Varshavchik2013-08-19 16:39:41 -0400
committerSam Varshavchik2013-08-25 14:43:51 -0400
commit9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch)
tree7a81a04cb51efb078ee350859a64be2ebc6b8813 /bdbobj/bdbobj2.c
parenta9520698b770168d1f33d6301463bb70a19655ec (diff)
downloadcourier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2
Initial checkin
Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'bdbobj/bdbobj2.c')
-rw-r--r--bdbobj/bdbobj2.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/bdbobj/bdbobj2.c b/bdbobj/bdbobj2.c
new file mode 100644
index 0000000..d4311b7
--- /dev/null
+++ b/bdbobj/bdbobj2.c
@@ -0,0 +1,81 @@
+/*
+** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
+** distribution information.
+*/
+
+#include "config.h"
+#include <string.h>
+#include <stdlib.h>
+#include "bdbobj.h"
+
+char *bdbobj_firstkey(struct bdbobj *obj, size_t *keylen, char **val,
+ size_t *vallen)
+{
+DBT key, value;
+
+ if (!obj->has_dbf) return (0);
+
+ memset(&key, 0, sizeof(key));
+ memset(&value, 0, sizeof(value));
+
+#if DB_VERSION_MAJOR < 2
+ if ((*obj->dbf->seq)(obj->dbf, &key, &value, R_FIRST)) return (0);
+#else
+ if (obj->has_dbc)
+ {
+ (*obj->dbc->c_close)(obj->dbc);
+ obj->has_dbc=0;
+ }
+
+#if DB_VERSION_MAJOR > 2
+ if ((*obj->dbf->cursor)(obj->dbf, 0, &obj->dbc, 0)) return (0);
+#else
+#if DB_VERSION_MINOR >= 5
+ if ((*obj->dbf->cursor)(obj->dbf, 0, &obj->dbc, 0)) return (0);
+#else
+ if ((*obj->dbf->cursor)(obj->dbf, 0, &obj->dbc)) return (0);
+#endif
+#endif
+ obj->has_dbc=1;
+
+ if ((*obj->dbc->c_get)(obj->dbc, &key, &value, DB_FIRST)) return (0);
+#endif
+ *keylen=key.size;
+ *vallen=value.size;
+ if ((*val=(char *)malloc(*vallen)) == 0) return (0);
+
+ memcpy(*val, value.data, *vallen);
+ return ((char *)key.data);
+}
+
+char *bdbobj_nextkey(struct bdbobj *obj, size_t *keylen, char **val,
+ size_t *vallen)
+{
+DBT key, value;
+
+ if (!obj->has_dbf) return (0);
+
+ memset(&key, 0, sizeof(key));
+ memset(&value, 0, sizeof(value));
+
+#if DB_VERSION_MAJOR < 2
+ if ((*obj->dbf->seq)(obj->dbf, &key, &value, R_NEXT)) return (0);
+#else
+ if (!obj->has_dbc) return (0);
+
+ if ((*obj->dbc->c_get)(obj->dbc, &key, &value, DB_NEXT))
+ {
+ (*obj->dbc->c_close)(obj->dbc);
+ obj->has_dbc=0;
+ }
+#endif
+
+ *keylen=key.size;
+ *vallen=value.size;
+ if ((*val=(char *)malloc(*vallen + 1)) == 0) return (0);
+
+ memcpy(*val, value.data, *vallen);
+ (*val)[*vallen]=0;
+
+ return ((char *)key.data);
+}