File: db_ver.c

package info (click to toggle)
man-db 2.3.10-65
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 2,440 kB
  • ctags: 1,826
  • sloc: ansic: 12,508; lex: 925; makefile: 642; sh: 328; sed: 93; perl: 62
file content (86 lines) | stat: -rw-r--r-- 1,644 bytes parent folder | download | duplicates (3)
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
/*
 * dbver.c: code to read, write and identify the database version no.
 *  
 * Copyright (C), 1994, 1995, Graeme W. Wilford. (Wilf.)
 *
 * You may distribute under the terms of the GNU Library General Public
 * License as specified in the file COPYING.LIB that comes with this
 * distribution.
 *
 * Mon Aug 18 20:35:30 BST 1994  Wilf. (G.Wilford@ee.surrey.ac.uk) 
 */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#include <stdio.h>

#ifdef STDC_HEADERS
#include <stdlib.h>
#endif /* STDC_HEADERS */

#define NLS_SET	db_verSet
#include <libintl.h>
#define _(String) gettext (String)

#include "manconfig.h"
#include "lib/error.h"
#include "mydbm.h"

static datum content;

static int dbver(MYDBM_FILE dbf)
{
	datum key;

	key.dptr = VER_KEY;
	key.dsize = sizeof VER_KEY;

	content = MYDBM_FETCH(dbf, key);

	if (content.dptr == NULL)
		return -1;
	else if (strcmp(content.dptr, VER_ID) != 0)
		return 1;
	else
		return 0;

}

void dbver_wr(MYDBM_FILE dbf)
{
	datum key, content;

	key.dptr = VER_KEY;
	key.dsize = sizeof VER_KEY;
	content.dptr = VER_ID;
	content.dsize = sizeof VER_ID;
	
	if (MYDBM_INSERT(dbf, key, content) != 0)
		error (FATAL, 0,
		       _( 
		       	       "fatal: unable to insert version identifier into %s"),
		       	       database);
}

int dbver_rd(MYDBM_FILE dbf)
{
	int status;

	status = dbver(dbf);
	
	if (status == -1)
		error (0, 0, _( "warning: %s has no version identifier"),
		       database);
	else if (status == 1)
		error (0, 0,
		       _( "warning: %s is version %s, expecting %s"),
		       database, content.dptr, VER_ID);
	else {
		MYDBM_FREE(content.dptr);
		return 0;
	}

	return 1;
}