/* This file is part of GDBM, the GNU data base manager.
Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013,
2016 Free Software Foundation, Inc.
GDBM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GDBM 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
#include "gdbmtool.h"
#include "gdbm.h"
#include "gram.h"
#include <errno.h>
#include <ctype.h>
#include <signal.h>
#include <pwd.h>
#include <sys/ioctl.h>
#ifdef HAVE_SYS_TERMIOS_H
# include <sys/termios.h>
#endif
#include <stdarg.h>
#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif
char *file_name = NULL; /* Database file name */
GDBM_FILE gdbm_file = NULL; /* Database to operate upon */
datum key_data; /* Current key */
datum return_data; /* Current data */
int open_mode; /* Default open mode */
#define SIZE_T_MAX ((size_t)-1)
unsigned input_line;
static int
opendb (char *dbname)
{
int cache_size = 0;
int block_size = 0;
int flags = 0;
int filemode;
GDBM_FILE db;
switch (variable_get ("cachesize", VART_INT, (void**) &cache_size))
{
case VAR_OK:
case VAR_ERR_NOTSET:
break;
default:
abort ();
}
switch (variable_get ("blocksize", VART_INT, (void**) &block_size))
{
case VAR_OK:
case VAR_ERR_NOTSET:
break;
default:
abort ();
}
if (!variable_is_true ("lock"))
flags |= GDBM_NOLOCK;
if (!variable_is_true ("mmap"))
flags |= GDBM_NOMMAP;
if (variable_is_true ("sync"))
flags |= GDBM_SYNC;
if (open_mode == GDBM_NEWDB)
{
if (interactive && variable_is_true ("confirm") &&
access (dbname, F_OK) == 0)
{
if (!getyn (_("database %s already exists; overwrite"), dbname))
return 1;
}
}
if (variable_get ("filemode", VART_INT, (void**) &filemode))
abort ();
db = gdbm_open (dbname, block_size, open_mode | flags, f
|