aboutsummaryrefslogtreecommitdiff
path: root/tests/gtdel.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-08-02 20:33:25 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2011-08-02 20:33:25 +0000
commit01ffbc46d8d357ba11088d8a2c3a38df856a078d (patch)
tree3b18fe5b10cfd98e42b9bedfacf10ae79cac0029 /tests/gtdel.c
parent8330c0e65abad8a0ebb6430d2c2de3e534c83a11 (diff)
downloadgdbm-01ffbc46d8d357ba11088d8a2c3a38df856a078d.tar.gz
gdbm-01ffbc46d8d357ba11088d8a2c3a38df856a078d.tar.bz2
Add delete tests.
Diffstat (limited to 'tests/gtdel.c')
-rw-r--r--tests/gtdel.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/gtdel.c b/tests/gtdel.c
new file mode 100644
index 0000000..6826532
--- /dev/null
+++ b/tests/gtdel.c
@@ -0,0 +1,112 @@
1/* This file is part of GDBM test suite.
2 Copyright (C) 2011 Free Software Foundation, Inc.
3
4 GDBM is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 GDBM is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GDBM. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include "autoconf.h"
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include "gdbm.h"
22
23const char *
24canonical_progname (const char *str)
25{
26 const char *p;
27
28 p = strrchr (str, '/');
29 if (p)
30 p++;
31 else
32 p = str;
33 if (strncmp (p, "lt-", 3) == 0)
34 p += 3;
35 return p;
36}
37
38int
39main (int argc, char **argv)
40{
41 const char *progname = canonical_progname (argv[0]);
42 const char *dbname;
43 datum key;
44 int flags = 0;
45 GDBM_FILE dbf;
46 int data_z = 0;
47 int rc = 0;
48
49 while (--argc)
50 {
51 char *arg = *++argv;
52
53 if (strcmp (arg, "-h") == 0)
54 {
55 printf ("usage: %s [-null] [-nolock] [-nommap] [-sync] DBFILE KEY [KEY...]\n",
56 progname);
57 exit (0);
58 }
59 else if (strcmp (arg, "-null") == 0)
60 data_z = 1;
61 else if (strcmp (arg, "-nolock") == 0)
62 flags |= GDBM_NOLOCK;
63 else if (strcmp (arg, "-nommap") == 0)
64 flags |= GDBM_NOMMAP;
65 else if (strcmp (arg, "-sync") == 0)
66 flags |= GDBM_SYNC;
67 else if (strcmp (arg, "--") == 0)
68 {
69 --argc;
70 ++argv;
71 break;
72 }
73 else if (arg[0] == '-')
74 {
75 fprintf (stderr, "%s: unknown option %s\n", progname, arg);
76 exit (1);
77 }
78 else
79 break;
80 }
81
82 if (argc < 2)
83 {
84 fprintf (stderr, "%s: wrong arguments\n", progname);
85 exit (1);
86 }
87 dbname = *argv;
88
89 dbf = gdbm_open (dbname, 0, GDBM_WRITER|flags, 0, NULL);
90 if (!dbf)
91 {
92 fprintf (stderr, "gdbm_open failed: %s\n", gdbm_strerror (gdbm_errno));
93 exit (1);
94 }
95
96 while (--argc)
97 {
98 char *arg = *++argv;
99
100 key.dptr = arg;
101 key.dsize = strlen (arg) + !!data_z;
102
103 if (gdbm_delete(dbf, key))
104 {
105 fprintf (stderr, "%s: cannot delete %s: %s\n",
106 progname, arg, gdbm_strerror (gdbm_errno));
107 rc = 2;
108 }
109 }
110 gdbm_close (dbf);
111 exit (rc);
112}

Return to:

Send suggestions and report system problems to the System administrator.