aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-07-09 08:40:04 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2016-07-09 08:47:16 +0300
commit479a469033903a76b9c073806037dd66176f3da0 (patch)
tree2841b611288f9343868e6ded82909b096a62e121
parent2efd8358711ab3ea6c0ecaab75d195837b4b3e37 (diff)
downloadgdbm-479a469033903a76b9c073806037dd66176f3da0.tar.gz
gdbm-479a469033903a76b9c073806037dd66176f3da0.tar.bz2
Per-database error state.
Last error code is stored in the database file structure as well as in the global gdbm_errno. Special functions are provided for retrieving and clearing the last error state. * src/gdbmdefs.h (gdbm_file_info): New member: last_error * src/gdbm.h.in (gdbm_last_errno, gdbm_set_errno) (gdbm_clear_error): New protos. * src/gdbmerrno.c (gdbm_last_errno, gdbm_set_errno) (gdbm_clear_error): New functions * NEWS: Update. * compat/dbminit.c: Use gdbm_set_errno to set error state. * compat/dbmopen.c: Likewise. * src/bucket.c: Likewise. * src/findkey.c: Likewise. * src/gdbm_load.c: Likewise. * src/gdbmcount.c: Likewise. * src/gdbmdelete.c: Likewise. * src/gdbmdump.c: Likewise. * src/gdbmexists.c: Likewise. * src/gdbmexp.c: Likewise. * src/gdbmfetch.c: Likewise. * src/gdbmimp.c: Likewise. * src/gdbmload.c: Likewise. * src/gdbmopen.c: Likewise. * src/gdbmreorg.c: Likewise. * src/gdbmseq.c: Likewise. * src/gdbmsetopt.c: Likewise. * src/gdbmstore.c: Likewise. * src/gdbmsync.c: Likewise. * src/mmap.c: Likewise.
-rw-r--r--NEWS10
-rw-r--r--compat/dbminit.c2
-rw-r--r--compat/dbmopen.c24
-rw-r--r--src/bucket.c8
-rw-r--r--src/findkey.c2
-rw-r--r--src/gdbm.h.in4
-rw-r--r--src/gdbm_load.c6
-rw-r--r--src/gdbmcount.c5
-rw-r--r--src/gdbmdefs.h6
-rw-r--r--src/gdbmdelete.c4
-rw-r--r--src/gdbmdump.c18
-rw-r--r--src/gdbmerrno.c36
-rw-r--r--src/gdbmexists.c4
-rw-r--r--src/gdbmexp.c12
-rw-r--r--src/gdbmfetch.c4
-rw-r--r--src/gdbmimp.c12
-rw-r--r--src/gdbmload.c14
-rw-r--r--src/gdbmopen.c65
-rw-r--r--src/gdbmreorg.c20
-rw-r--r--src/gdbmseq.c10
-rw-r--r--src/gdbmsetopt.c79
-rw-r--r--src/gdbmstore.c12
-rw-r--r--src/gdbmsync.c6
-rw-r--r--src/mmap.c8
24 files changed, 221 insertions, 150 deletions
diff --git a/NEWS b/NEWS
index a4f1129..4efabdb 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
1GNU dbm NEWS -- history of user-visible changes. 2016-07-08 1GNU dbm NEWS -- history of user-visible changes. 2016-07-09
2Copyright (C) 1990-2016 Free Software Foundation, Inc. 2Copyright (C) 1990-2016 Free Software Foundation, Inc.
3See the end of file for copying conditions. 3See the end of file for copying conditions.
4 4
@@ -21,6 +21,14 @@ return.
21The gdbm_fetch function no longer aborts on memory allocation errors. 21The gdbm_fetch function no longer aborts on memory allocation errors.
22Instead it sets gdbm_errno to GDBM_MALLOC_ERROR and returns NULL datum. 22Instead it sets gdbm_errno to GDBM_MALLOC_ERROR and returns NULL datum.
23 23
24* Per-database error codes
25
26* New functions
27
28** gdbm_last_errno
29
30** gdbm_clear_error
31
24 32
25Version 1.12, 2016-05-16 33Version 1.12, 2016-05-16
26 34
diff --git a/compat/dbminit.c b/compat/dbminit.c
index 94ddc22..f5c5a65 100644
--- a/compat/dbminit.c
+++ b/compat/dbminit.c
@@ -48,7 +48,7 @@ dbminit (char *file)
48 /* Did we successfully open the file? */ 48 /* Did we successfully open the file? */
49 if (_gdbm_file == NULL) 49 if (_gdbm_file == NULL)
50 { 50 {
51 gdbm_errno = GDBM_FILE_OPEN_ERROR; 51 gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 1);
52 return -1; 52 return -1;
53 } 53 }
54 } 54 }
diff --git a/compat/dbmopen.c b/compat/dbmopen.c
index 7a5127e..f8df3e3 100644
--- a/compat/dbmopen.c
+++ b/compat/dbmopen.c
@@ -71,7 +71,7 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
71 71
72 if (fstat (pagfd, &pagst)) 72 if (fstat (pagfd, &pagst))
73 { 73 {
74 gdbm_errno = GDBM_FILE_OPEN_ERROR; /* FIXME: special code? */ 74 gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 1); /* FIXME: special code? */
75 return -1; 75 return -1;
76 } 76 }
77 77
@@ -89,14 +89,14 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
89 return pagfd; 89 return pagfd;
90 else 90 else
91 { 91 {
92 gdbm_errno = GDBM_FILE_OPEN_ERROR; 92 gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 1);
93 return -1; 93 return -1;
94 } 94 }
95 } 95 }
96 } 96 }
97 else 97 else
98 { 98 {
99 gdbm_errno = GDBM_FILE_OPEN_ERROR; 99 gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 1);
100 return -1; 100 return -1;
101 } 101 }
102 } 102 }
@@ -104,7 +104,7 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
104 /* ok */; 104 /* ok */;
105 else if (st.st_size != DEF_DIR_SIZE) 105 else if (st.st_size != DEF_DIR_SIZE)
106 { 106 {
107 gdbm_errno = GDBM_BAD_MAGIC_NUMBER; 107 gdbm_set_errno (NULL, GDBM_BAD_MAGIC_NUMBER, 1);
108 return -1; 108 return -1;
109 } 109 }
110 else 110 else
@@ -112,13 +112,13 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
112 fd = open (file_name, flags); 112 fd = open (file_name, flags);
113 if (fd == -1) 113 if (fd == -1)
114 { 114 {
115 gdbm_errno = GDBM_FILE_OPEN_ERROR; 115 gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 1);
116 return fd; 116 return fd;
117 } 117 }
118 118
119 if (read (fd, dirbuf, sizeof (dirbuf)) != sizeof (dirbuf)) 119 if (read (fd, dirbuf, sizeof (dirbuf)) != sizeof (dirbuf))
120 { 120 {
121 gdbm_errno = GDBM_FILE_OPEN_ERROR; 121 gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 1);
122 close (fd); 122 close (fd);
123 return -1; 123 return -1;
124 } 124 }
@@ -135,7 +135,7 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
135 return fd; 135 return fd;
136 } 136 }
137 close (fd); 137 close (fd);
138 gdbm_errno = GDBM_BAD_MAGIC_NUMBER; 138 gdbm_set_errno (NULL, GDBM_BAD_MAGIC_NUMBER, 1);
139 return -1; 139 return -1;
140 } 140 }
141 } 141 }
@@ -151,7 +151,7 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
151 151
152 if (write (fd, dirbuf, sizeof (dirbuf)) != sizeof (dirbuf)) 152 if (write (fd, dirbuf, sizeof (dirbuf)) != sizeof (dirbuf))
153 { 153 {
154 gdbm_errno = GDBM_FILE_WRITE_ERROR; 154 gdbm_set_errno (NULL, GDBM_FILE_WRITE_ERROR, 1);
155 close (fd); 155 close (fd);
156 fd = -1; 156 fd = -1;
157 } 157 }
@@ -168,7 +168,7 @@ ndbm_open_dir_file (const char *base, int pagfd, int mode)
168 168
169 if (!file_name) 169 if (!file_name)
170 { 170 {
171 gdbm_errno = GDBM_MALLOC_ERROR; 171 gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 1);
172 return -1; 172 return -1;
173 } 173 }
174 fd = ndbm_open_dir_file0 (strcat (strcpy (file_name, base), DIRSUF), 174 fd = ndbm_open_dir_file0 (strcat (strcpy (file_name, base), DIRSUF),
@@ -212,7 +212,7 @@ dbm_open (char *file, int flags, int mode)
212 pag_file = (char *) malloc (strlen (file) + 5); 212 pag_file = (char *) malloc (strlen (file) + 5);
213 if (!pag_file) 213 if (!pag_file)
214 { 214 {
215 gdbm_errno = GDBM_MALLOC_ERROR; /* For the hell of it. */ 215 gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 1); /* For the hell of it. */
216 return NULL; 216 return NULL;
217 } 217 }
218 218
@@ -250,7 +250,7 @@ dbm_open (char *file, int flags, int mode)
250 if (!dbm) 250 if (!dbm)
251 { 251 {
252 free (pag_file); 252 free (pag_file);
253 gdbm_errno = GDBM_MALLOC_ERROR; /* For the hell of it. */ 253 gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 1); /* For the hell of it. */
254 return NULL; 254 return NULL;
255 } 255 }
256 256
@@ -259,7 +259,7 @@ dbm_open (char *file, int flags, int mode)
259 /* Did we successfully open the file? */ 259 /* Did we successfully open the file? */
260 if (dbm->file == NULL) 260 if (dbm->file == NULL)
261 { 261 {
262 gdbm_errno = GDBM_FILE_OPEN_ERROR; 262 gdbm_set_errno (dbm, GDBM_FILE_OPEN_ERROR, 1);
263 free (dbm); 263 free (dbm);
264 dbm = NULL; 264 dbm = NULL;
265 } 265 }
diff --git a/src/bucket.c b/src/bucket.c
index c9a951c..ee0e157 100644
--- a/src/bucket.c
+++ b/src/bucket.c
@@ -1,8 +1,8 @@
1/* bucket.c - The routines for playing with hash buckets. */ 1/* bucket.c - The routines for playing with hash buckets. */
2 2
3/* This file is part of GDBM, the GNU data base manager. 3/* This file is part of GDBM, the GNU data base manager.
4 Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013 Free Software Foundation, 4 Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013,
5 Inc. 5 2016 Free Software Foundation, Inc.
6 6
7 GDBM is free software; you can redistribute it and/or modify 7 GDBM is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
@@ -131,13 +131,13 @@ _gdbm_read_bucket_at (GDBM_FILE dbf, off_t off, hash_bucket *bucket,
131 file_pos = __lseek (dbf, off, SEEK_SET); 131 file_pos = __lseek (dbf, off, SEEK_SET);
132 if (file_pos != off) 132 if (file_pos != off)
133 { 133 {
134 gdbm_errno = GDBM_FILE_SEEK_ERROR; 134 gdbm_set_errno (dbf, GDBM_FILE_SEEK_ERROR, 1);
135 return -1; 135 return -1;
136 } 136 }
137 rc = _gdbm_full_read (dbf, bucket, size); 137 rc = _gdbm_full_read (dbf, bucket, size);
138 if (rc) 138 if (rc