1 05_handle-short-read.patch
3 diff -urNad a/bucket.c b/bucket.c
4 --- a/bucket.c 1999-05-19 01:16:05.000000000 +0100
5 +++ b/bucket.c 2006-04-24 03:18:01.000000000 +0100
13 /* Initializing a new hash buckets sets all bucket entries to -1 hash value. */
18 off_t bucket_adr; /* The address of the correct hash bucket. */
19 - int num_bytes; /* The number of bytes read. */
20 + int num_bytes = 0; /* The total number of bytes read. */
21 + int bytes_read; /* Number of bytes read in this syscall */
22 off_t file_pos; /* The return address for lseek. */
23 register int index; /* Loop index. */
26 if (file_pos != bucket_adr)
27 _gdbm_fatal (dbf, "lseek error");
29 - num_bytes = read (dbf->desc, dbf->bucket, dbf->header->bucket_size);
32 + bytes_read = read (dbf->desc, dbf->bucket+num_bytes, dbf->header->bucket_size-num_bytes);
33 + if (bytes_read > 0) num_bytes += bytes_read;
35 + while ((bytes_read > 0 || (bytes_read == -1 && errno == EINTR)) && num_bytes < dbf->header->bucket_size);
36 if (num_bytes != dbf->header->bucket_size)
37 _gdbm_fatal (dbf, "read error");
39 diff -urNad a/falloc.c b/falloc.c
40 --- a/falloc.c 2006-04-24 03:17:54.000000000 +0100
41 +++ b/falloc.c 2006-04-24 03:18:01.000000000 +0100
49 /* The forward definitions for this file. See the functions for
50 the definition of the function. */
55 - int num_bytes; /* For use with the read system call. */
56 + int num_bytes = 0; /* For use with the read system call. */
57 + int bytes_read; /* For use with the read system call. */
58 off_t file_pos; /* For use with the lseek system call. */
63 file_pos = lseek (dbf->desc, new_el.av_adr, L_SET);
64 if (file_pos != new_el.av_adr) _gdbm_fatal (dbf, "lseek error");
65 - num_bytes = read (dbf->desc, new_blk, new_el.av_size);
68 + bytes_read = read (dbf->desc, new_blk+num_bytes, new_el.av_size-num_bytes);
69 + if (bytes_read > 0) num_bytes += bytes_read;
71 + while ((bytes_read > 0 || (bytes_read == -1 && errno == EINTR)) && num_bytes < new_el.av_size);
72 if (num_bytes != new_el.av_size) _gdbm_fatal (dbf, "read error");
74 /* Add the elements from the new block to the header. */
75 diff -urNad a/findkey.c b/findkey.c
76 --- a/findkey.c 1999-05-19 01:16:06.000000000 +0100
77 +++ b/findkey.c 2006-04-24 03:18:01.000000000 +0100
85 /* Read the data found in bucket entry ELEM_LOC in file DBF and
90 - int num_bytes; /* For seeking and reading. */
91 + int num_bytes = 0; /* For seeking and reading. */
95 data_cache_elem *data_ca;
98 /* Is it already in the cache? */
99 if (dbf->cache_entry->ca_data.elem_loc == elem_loc)
101 dbf->bucket->h_table[elem_loc].data_pointer, L_SET);
102 if (file_pos != dbf->bucket->h_table[elem_loc].data_pointer)
103 _gdbm_fatal (dbf, "lseek error");
104 - num_bytes = read (dbf->desc, data_ca->dptr, key_size+data_size);
107 + bytes_read = read (dbf->desc, data_ca->dptr+num_bytes, key_size+data_size-num_bytes);
108 + if (bytes_read > 0) num_bytes += bytes_read;
110 + while ((bytes_read > 0 || (bytes_read == -1 && errno == EINTR)) && num_bytes < key_size+data_size);
111 if (num_bytes != key_size+data_size) _gdbm_fatal (dbf, "read error");
113 return data_ca->dptr;