aboutsummaryrefslogtreecommitdiff
path: root/src/gdbmstore.c
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 /src/gdbmstore.c
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.
Diffstat (limited to 'src/gdbmstore.c')
-rw-r--r--src/gdbmstore.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/gdbmstore.c b/src/gdbmstore.c
index 3ba882e..f166ba9 100644
--- a/src/gdbmstore.c
+++ b/src/gdbmstore.c
@@ -47,26 +47,26 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
47 int new_size; /* Used in allocating space. */ 47 int new_size; /* Used in allocating space. */
48 int rc; 48 int rc;
49 49
50 /* First check to make sure this guy is a writer. */ 50 /* First check to make sure this guy is a writer. */
51 if (dbf->read_write == GDBM_READER) 51 if (dbf->read_write == GDBM_READER)
52 { 52 {
53 gdbm_errno = GDBM_READER_CANT_STORE; 53 gdbm_set_errno (dbf, GDBM_READER_CANT_STORE, 0);
54 return -1; 54 return -1;
55 } 55 }
56 56
57 /* Check for illegal data values. A NULL dptr field is illegal because 57 /* Check for illegal data values. A NULL dptr field is illegal because
58 NULL dptr returned by a lookup procedure indicates an error. */ 58 NULL dptr returned by a lookup procedure indicates an error. */
59 if ((key.dptr == NULL) || (content.dptr == NULL)) 59 if ((key.dptr == NULL) || (content.dptr == NULL))
60 { 60 {
61 gdbm_errno = GDBM_ILLEGAL_DATA; 61 gdbm_set_errno (dbf, GDBM_ILLEGAL_DATA, 0);
62 return -1; 62 return -1;
63 } 63 }
64 64
65 /* Initialize the gdbm_errno variable. */ 65 /* Initialize the gdbm_errno variable. */
66 gdbm_errno = GDBM_NO_ERROR; 66 gdbm_set_errno (dbf, GDBM_NO_ERROR, 0);
67 67
68 /* Look for the key in the file. 68 /* Look for the key in the file.
69 A side effect loads the correct bucket and calculates the hash value. */ 69 A side effect loads the correct bucket and calculates the hash value. */
70 elem_loc = _gdbm_findkey (dbf, key, NULL, &new_hash_val); 70 elem_loc = _gdbm_findkey (dbf, key, NULL, &new_hash_val);
71 71
72 /* Initialize these. */ 72 /* Initialize these. */
@@ -91,17 +91,19 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
91 /* Just reuse the same address! */ 91 /* Just reuse the same address! */
92 file_adr = free_adr; 92 file_adr = free_adr;
93 } 93 }
94 } 94 }
95 else 95 else
96 { 96 {
97 gdbm_errno = GDBM_CANNOT_REPLACE; 97 gdbm_set_errno (dbf, GDBM_CANNOT_REPLACE, 0);
98 return 1; 98 return 1;
99 } 99 }
100 } 100 }
101 else if (gdbm_errno != GDBM_ITEM_NOT_FOUND) 101 else if (gdbm_errno == GDBM_ITEM_NOT_FOUND)
102 gdbm_set_errno (dbf, GDBM_NO_ERROR, 0); //clear error state
103 else
102 return -1; 104 return -1;
103 105
104 /* Get the file address for the new space. 106 /* Get the file address for the new space.
105 (Current bucket's free space is first place to look.) */ 107 (Current bucket's free space is first place to look.) */
106 if (file_adr == 0) 108 if (file_adr == 0)
107 file_adr = _gdbm_alloc (dbf, new_size); 109 file_adr = _gdbm_alloc (dbf, new_size);

Return to:

Send suggestions and report system problems to the System administrator.