summaryrefslogtreecommitdiffstats
path: root/libdb/db_ver.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 19:37:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 19:37:10 +0000
commitc9addba5cc770d2d231b34f6739f32c6be8690f1 (patch)
treec643da154a95a1d163137135050bb47858a1654e /libdb/db_ver.c
parentInitial commit. (diff)
downloadman-db-c9addba5cc770d2d231b34f6739f32c6be8690f1.tar.xz
man-db-c9addba5cc770d2d231b34f6739f32c6be8690f1.zip
Adding upstream version 2.12.0.upstream/2.12.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libdb/db_ver.c')
-rw-r--r--libdb/db_ver.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/libdb/db_ver.c b/libdb/db_ver.c
new file mode 100644
index 0000000..fac9c5a
--- /dev/null
+++ b/libdb/db_ver.c
@@ -0,0 +1,87 @@
+/*
+ * dbver.c: code to read, write and identify the database version no.
+ *
+ * Copyright (C) 1994, 1995 Graeme W. Wilford. (Wilf.)
+ * Copyright (C) 2001, 2002 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
+ *
+ * Mon Aug 18 20:35:30 BST 1994 Wilf. (G.Wilford@ee.surrey.ac.uk)
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "gettext.h"
+#define _(String) gettext (String)
+
+#include "xalloc.h"
+
+#include "manconfig.h"
+
+#include "debug.h"
+#include "fatal.h"
+
+#include "mydbm.h"
+
+int dbver_rd (MYDBM_FILE dbfile)
+{
+ datum key, content;
+
+ memset (&key, 0, sizeof key);
+
+ MYDBM_SET (key, xstrdup (VER_KEY));
+
+ content = MYDBM_FETCH (dbfile, key);
+
+ MYDBM_FREE_DPTR (key);
+
+ if (MYDBM_DPTR (content) == NULL) {
+ debug (_("warning: %s has no version identifier\n"),
+ dbfile->name);
+ return 1;
+ } else if (!STREQ (MYDBM_DPTR (content), VER_ID)) {
+ debug (_("warning: %s is version %s, expecting %s\n"),
+ dbfile->name, MYDBM_DPTR (content), VER_ID);
+ MYDBM_FREE_DPTR (content);
+ return 1;
+ } else {
+ MYDBM_FREE_DPTR (content);
+ return 0;
+ }
+}
+
+void dbver_wr (MYDBM_FILE dbfile)
+{
+ datum key, content;
+
+ memset (&key, 0, sizeof key);
+ memset (&content, 0, sizeof content);
+
+ MYDBM_SET (key, xstrdup (VER_KEY));
+ MYDBM_SET (content, xstrdup (VER_ID));
+
+ if (MYDBM_INSERT (dbfile, key, content) != 0)
+ fatal (0,
+ _("fatal: unable to insert version identifier into %s"),
+ dbfile->name);
+
+ MYDBM_FREE_DPTR (key);
+ MYDBM_FREE_DPTR (content);
+}