(root)/
man-db-2.12.0/
libdb/
db_ver.c
       1  /*
       2   * dbver.c: code to read, write and identify the database version no.
       3   *
       4   * Copyright (C) 1994, 1995 Graeme W. Wilford. (Wilf.)
       5   * Copyright (C) 2001, 2002 Colin Watson.
       6   *
       7   * This library is free software; you can redistribute it and/or
       8   * modify it under the terms of the GNU Library General Public
       9   * License as published by the Free Software Foundation; either
      10   * version 2 of the License, or (at your option) any later version.
      11   *
      12   * This library is distributed in the hope that it will be useful,
      13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15   * Library General Public License for more details.
      16   *
      17   * You should have received a copy of the GNU Library General Public
      18   * License along with this library; if not, write to the Free Software
      19   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
      20   *
      21   * Mon Aug 18 20:35:30 BST 1994  Wilf. (G.Wilford@ee.surrey.ac.uk)
      22   */
      23  
      24  #ifdef HAVE_CONFIG_H
      25  #  include "config.h"
      26  #endif
      27  
      28  #include <string.h>
      29  #include <stdlib.h>
      30  
      31  #include "gettext.h"
      32  #define _(String) gettext (String)
      33  
      34  #include "xalloc.h"
      35  
      36  #include "manconfig.h"
      37  
      38  #include "debug.h"
      39  #include "fatal.h"
      40  
      41  #include "mydbm.h"
      42  
      43  int dbver_rd (MYDBM_FILE dbfile)
      44  {
      45  	datum key, content;
      46  
      47  	memset (&key, 0, sizeof key);
      48  
      49  	MYDBM_SET (key, xstrdup (VER_KEY));
      50  
      51  	content = MYDBM_FETCH (dbfile, key);
      52  
      53  	MYDBM_FREE_DPTR (key);
      54  
      55  	if (MYDBM_DPTR (content) == NULL) {
      56  		debug (_("warning: %s has no version identifier\n"),
      57  		       dbfile->name);
      58  		return 1;
      59  	} else if (!STREQ (MYDBM_DPTR (content), VER_ID)) {
      60  		debug (_("warning: %s is version %s, expecting %s\n"),
      61  		       dbfile->name, MYDBM_DPTR (content), VER_ID);
      62  		MYDBM_FREE_DPTR (content);
      63  		return 1;
      64  	} else {
      65  		MYDBM_FREE_DPTR (content);
      66  		return 0;
      67  	}
      68  }
      69  
      70  void dbver_wr (MYDBM_FILE dbfile)
      71  {
      72  	datum key, content;
      73  
      74  	memset (&key, 0, sizeof key);
      75  	memset (&content, 0, sizeof content);
      76  
      77  	MYDBM_SET (key, xstrdup (VER_KEY));
      78  	MYDBM_SET (content, xstrdup (VER_ID));
      79  
      80  	if (MYDBM_INSERT (dbfile, key, content) != 0)
      81  		fatal (0,
      82  		       _("fatal: unable to insert version identifier into %s"),
      83  		       dbfile->name);
      84  
      85  	MYDBM_FREE_DPTR (key);
      86  	MYDBM_FREE_DPTR (content);
      87  }