summaryrefslogtreecommitdiffabout
path: root/src/gdbmstore.c
authorSergey Poznyakoff <gray@gnu.org.ua>2011-10-05 13:06:15 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-10-05 13:06:15 (GMT)
commitd74b094cdcd25b5ce493640873d910a3b788fafe (patch) (side-by-side diff)
tree6b952a6032b11dee04cec340af54d03ad63cce6e /src/gdbmstore.c
parente0db2284c372ca8be529dec2ea3e78842e5486f3 (diff)
downloadgdbm-d74b094cdcd25b5ce493640873d910a3b788fafe.tar.gz
gdbm-d74b094cdcd25b5ce493640873d910a3b788fafe.tar.bz2
Fix bug #150.
Tolerate I/O operations returning less bytes than expected. Retry I/O if possible. * src/fullio.c: New file. * src/Makefile.am (libgdbm_la_SOURCES): Add fullio.c * src/proto.h (_gdbm_full_read) (_gdbm_full_write): New protos. * src/gdbmerrno.c (gdbm_errlist): Add entry for GDBM_FILE_EOF. * src/bucket.c: Use _gdbm_full_{read|write}. * src/falloc.c: Likewise. * src/findkey.c: Likewise. * src/gdbmopen.c: Likewise. * src/gdbmstore.c: Likewise. * src/testgdbm.c: Likewise. * src/update.c: Likewise.
Diffstat (limited to 'src/gdbmstore.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/gdbmstore.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/gdbmstore.c b/src/gdbmstore.c
index 5f1bb67..367cc4f 100644
--- a/src/gdbmstore.c
+++ b/src/gdbmstore.c
@@ -42,12 +42,11 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
int elem_loc; /* The location in hash bucket. */
off_t file_adr; /* The address of new space in the file. */
off_t file_pos; /* The position after a lseek. */
- int num_bytes; /* Used for error detection. */
off_t free_adr; /* For keeping track of a freed section. */
int free_size;
int new_size; /* Used in allocating space. */
char *temp; /* Used in _gdbm_findkey call. */
-
+ int rc;
/* First check to make sure this guy is a writer. */
if (dbf->read_write == GDBM_READER)
@@ -139,10 +138,12 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
/* Write the data to the file. */
file_pos = __lseek (dbf, file_adr, L_SET);
if (file_pos != file_adr) _gdbm_fatal (dbf, _("lseek error"));
- num_bytes = __write (dbf, key.dptr, key.dsize);
- if (num_bytes != key.dsize) _gdbm_fatal (dbf, _("write error"));
- num_bytes = __write (dbf, content.dptr, content.dsize);
- if (num_bytes != content.dsize) _gdbm_fatal (dbf, _("write error"));
+ rc = _gdbm_full_write (dbf, key.dptr, key.dsize);
+ if (rc)
+ _gdbm_fatal (dbf, gdbm_strerror (rc));
+ rc = _gdbm_full_write (dbf, content.dptr, content.dsize);
+ if (rc)
+ _gdbm_fatal (dbf, gdbm_strerror (rc));
/* Current bucket has changed. */
dbf->cache_entry->ca_changed = TRUE;

Return to:

Send suggestions and report system problems to the System administrator.