gdbm/gdbm-1.8.3-shortread.patch

114 lines
3.8 KiB
Diff
Raw Normal View History

2010-03-10 14:58:34 +00:00
05_handle-short-read.patch
diff -urNad a/bucket.c b/bucket.c
--- a/bucket.c 1999-05-19 01:16:05.000000000 +0100
+++ b/bucket.c 2006-04-24 03:18:01.000000000 +0100
@@ -31,7 +31,7 @@
#include "autoconf.h"
#include "gdbmdefs.h"
-
+#include <errno.h>
/* Initializing a new hash buckets sets all bucket entries to -1 hash value. */
void
@@ -68,7 +68,8 @@
int dir_index;
{
off_t bucket_adr; /* The address of the correct hash bucket. */
- int num_bytes; /* The number of bytes read. */
+ int num_bytes = 0; /* The total number of bytes read. */
+ int bytes_read; /* Number of bytes read in this syscall */
off_t file_pos; /* The return address for lseek. */
register int index; /* Loop index. */
@@ -111,7 +112,12 @@
if (file_pos != bucket_adr)
_gdbm_fatal (dbf, "lseek error");
- num_bytes = read (dbf->desc, dbf->bucket, dbf->header->bucket_size);
+ do
+ {
+ bytes_read = read (dbf->desc, dbf->bucket+num_bytes, dbf->header->bucket_size-num_bytes);
+ if (bytes_read > 0) num_bytes += bytes_read;
+ }
+ while ((bytes_read > 0 || (bytes_read == -1 && errno == EINTR)) && num_bytes < dbf->header->bucket_size);
if (num_bytes != dbf->header->bucket_size)
_gdbm_fatal (dbf, "read error");
}
diff -urNad a/falloc.c b/falloc.c
--- a/falloc.c 2006-04-24 03:17:54.000000000 +0100
+++ b/falloc.c 2006-04-24 03:18:01.000000000 +0100
@@ -31,7 +31,7 @@
#include "autoconf.h"
#include "gdbmdefs.h"
-
+#include <errno.h>
/* The forward definitions for this file. See the functions for
the definition of the function. */
@@ -174,7 +174,8 @@
pop_avail_block (dbf)
gdbm_file_info *dbf;
{
- int num_bytes; /* For use with the read system call. */
+ int num_bytes = 0; /* For use with the read system call. */
+ int bytes_read; /* For use with the read system call. */
off_t file_pos; /* For use with the lseek system call. */
avail_elem new_el;
avail_block *new_blk;
@@ -199,7 +200,12 @@
/* Read the block. */
file_pos = lseek (dbf->desc, new_el.av_adr, L_SET);
if (file_pos != new_el.av_adr) _gdbm_fatal (dbf, "lseek error");
- num_bytes = read (dbf->desc, new_blk, new_el.av_size);
+ do
+ {
+ bytes_read = read (dbf->desc, new_blk+num_bytes, new_el.av_size-num_bytes);
+ if (bytes_read > 0) num_bytes += bytes_read;
+ }
+ while ((bytes_read > 0 || (bytes_read == -1 && errno == EINTR)) && num_bytes < new_el.av_size);
if (num_bytes != new_el.av_size) _gdbm_fatal (dbf, "read error");
/* Add the elements from the new block to the header. */
diff -urNad a/findkey.c b/findkey.c
--- a/findkey.c 1999-05-19 01:16:06.000000000 +0100
+++ b/findkey.c 2006-04-24 03:18:01.000000000 +0100
@@ -31,6 +31,7 @@
#include "autoconf.h"
#include "gdbmdefs.h"
+#include <errno.h>
/* Read the data found in bucket entry ELEM_LOC in file DBF and
@@ -41,11 +42,12 @@
gdbm_file_info *dbf;
int elem_loc;
{
- int num_bytes; /* For seeking and reading. */
+ int num_bytes = 0; /* For seeking and reading. */
int key_size;
int data_size;
off_t file_pos;
data_cache_elem *data_ca;
+ int bytes_read;
/* Is it already in the cache? */
if (dbf->cache_entry->ca_data.elem_loc == elem_loc)
@@ -74,7 +76,12 @@
dbf->bucket->h_table[elem_loc].data_pointer, L_SET);
if (file_pos != dbf->bucket->h_table[elem_loc].data_pointer)
_gdbm_fatal (dbf, "lseek error");
- num_bytes = read (dbf->desc, data_ca->dptr, key_size+data_size);
+ do
+ {
+ bytes_read = read (dbf->desc, data_ca->dptr+num_bytes, key_size+data_size-num_bytes);
+ if (bytes_read > 0) num_bytes += bytes_read;
+ }
+ while ((bytes_read > 0 || (bytes_read == -1 && errno == EINTR)) && num_bytes < key_size+data_size);
if (num_bytes != key_size+data_size) _gdbm_fatal (dbf, "read error");
return data_ca->dptr;