From e0023883c6d2e6745a19e4b48e186ed156c1fca8 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 17:19:27 +0200 Subject: Adding upstream version 2.11.2. Signed-off-by: Daniel Baumann --- libdb/db_ver.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 libdb/db_ver.c (limited to 'libdb/db_ver.c') 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 +#include + +#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); +} -- cgit v1.2.3