summaryrefslogtreecommitdiff
path: root/libdb/db_xdbm.h
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2019-08-26 15:35:25 +0100
committerColin Watson <cjwatson@debian.org>2019-08-26 15:35:25 +0100
commite5716ea260f0a06c1559333e72f97f1b77f0ec8d (patch)
tree9c57f94f440b868d172e3cd024471207f4335a15 /libdb/db_xdbm.h
parentd986f98de23da09643e097227b2211910a63f6b3 (diff)
Order results manually for NDBM as well as GDBM
Commit 3a753221a3dddaf4870a86a4dca4771ed2cd80b3 in 2003 (!) worked around the fact that GDBM's firstkey/nextkey interface doesn't return ordered results. However, at least when using GDBM's NDBM compatibility interface, this may be true for NDBM too. Extend the manual result ordering code to cover both of these backends. * libdb/db_gdbm.c (parent_keys, datum_compare, datum_equals, datum_hash, datum_free, empty_datum, man_gdbm_firstkey, man_gdbm_nextkey, man_gdbm_close): Move to ... * libdb/db_xdbm.c (parent_keys, datum_compare, datum_equals, datum_hash, datum_free, empty_datum, man_xdbm_firstkey, man_xdbm_nextkey, man_xdbm_close): ... here (new file). * libdb/db_xdbm.h: New file. * libdb/db_gdbm.c (unsorted_firstkey, unsorted_nextkey, raw_close): New functions, wrapping gdbm_firstkey, gdbm_nextkey, and gdbm_close respectively. (man_gdbm_firstkey, man_gdbm_nextkey, man_gdbm_close): Add GDBM-specific wrappers for the generic man_xdbm_* functions. * libdb/db_ndbm.c (man_ndbm_close): Move NDBM-specific code ... (raw_close): ... here. (unsorted_firstkey, unsorted_nextkey): New functions, wrapping dbm_firstkey and dbm_nextkey respectively. (man_ndbm_close, man_ndbm_firstkey, man_ndbm_nextkey): Add NDBM-specific wrappers for the generic man_xdbm_* functions. * libdb/mydbm.h (man_ndbm_firstkey, man_ndbm_nextkey): Add prototypes. (MYDBM_FIRSTKEY) [NDBM]: Rewrite in terms of man_ndbm_firstkey. (MYDBM_NEXTKEY) [NDBM]: Rewrite in terms of man_ndbm_nextkey. * libdb/Makefile.am (libmandb_la_SOURCES): Add db_xdbm.c and db_xdbm.h. * NEWS: Document this.
Diffstat (limited to 'libdb/db_xdbm.h')
-rw-r--r--libdb/db_xdbm.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/libdb/db_xdbm.h b/libdb/db_xdbm.h
new file mode 100644
index 00000000..9d7f4bf7
--- /dev/null
+++ b/libdb/db_xdbm.h
@@ -0,0 +1,40 @@
+/*
+ * db_xdbm.c: interface to common code for gdbm and ndbm backends
+ *
+ * Copyright (C) 2019 Colin Watson.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef MAN_XDBM_H
+#define MAN_XDBM_H
+
+#if defined(GDBM) || defined(NDBM)
+
+#include "mydbm.h"
+
+typedef datum (*man_xdbm_unsorted_firstkey) (MYDBM_FILE dbf);
+typedef datum (*man_xdbm_unsorted_nextkey) (MYDBM_FILE dbf, datum key);
+typedef void (*man_xdbm_raw_close) (MYDBM_FILE dbf);
+
+datum man_xdbm_firstkey (MYDBM_FILE dbf,
+ man_xdbm_unsorted_firstkey firstkey,
+ man_xdbm_unsorted_nextkey nextkey);
+datum man_xdbm_nextkey (MYDBM_FILE dbf, datum key);
+void man_xdbm_close (MYDBM_FILE dbf, man_xdbm_raw_close raw_close);
+
+#endif /* GDBM || NDBM */
+
+#endif /* MAN_XDBM_H */