1
/********************************************************************\
2
* This program is free software; you can redistribute it and/or *
3
* modify it under the terms of the GNU General Public License as *
4
* published by the Free Software Foundation; either version 2 of *
5
* the License, or (at your option) any later version. *
7
* This program is distributed in the hope that it will be useful, *
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
10
* GNU General Public License for more details. *
12
* You should have received a copy of the GNU General Public License*
13
* along with this program; if not, contact: *
15
* Free Software Foundation Voice: +1-617-542-5942 *
16
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
17
* Boston, MA 02111-1307, USA gnu@gnu.org *
19
\********************************************************************/
29
#include <sys/types.h>
32
/* needed for db.h with 'gcc -ansi -pedantic' */
34
# define _BSD_SOURCE 1
60
#define ZERO(Dbt) memset (&(Dbt), sizeof (DBT), 0)
66
usage (const char *name)
68
fprintf (stderr, "Usage: %s database key1 value1 key2 value2 ...\n",
74
main (int argc, char *argv[])
81
memset (&info, 0, sizeof (info));
84
info.nelem = (argc-2)>>1>0 ? (argc-2)>>1 : 1;
97
database = dbopen (db_name, O_CREAT | O_RDWR, 0644, DB_HASH, &info);
100
fprintf (stderr, "Error opening database %s: %s\n",
101
db_name ? db_name : "",
102
strerror (errno) ? strerror (errno) : "");
106
for (i = 2; i < argc; i += 2)
115
key.size = strlen (key.data);
117
value.data = argv[i + 1];
118
value.size = strlen (value.data) + 1;
120
if (database->put (database, &key, &value, 0))
122
fprintf (stderr, "Error writing data.\n");
127
database->close (database);