1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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);
}
|