]> git.ipfire.org Git - ipfire-3.x.git/blob - compat-gdbm/patches/gdbm-1.8.3-shortread.patch
gdbm: Update to 1.10.
[ipfire-3.x.git] / compat-gdbm / patches / gdbm-1.8.3-shortread.patch
1 05_handle-short-read.patch
2
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
6 @@ -31,7 +31,7 @@
7 #include "autoconf.h"
8
9 #include "gdbmdefs.h"
10 -
11 +#include <errno.h>
12
13 /* Initializing a new hash buckets sets all bucket entries to -1 hash value. */
14 void
15 @@ -68,7 +68,8 @@
16 int dir_index;
17 {
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. */
24
25 @@ -111,7 +112,12 @@
26 if (file_pos != bucket_adr)
27 _gdbm_fatal (dbf, "lseek error");
28
29 - num_bytes = read (dbf->desc, dbf->bucket, dbf->header->bucket_size);
30 + do
31 + {
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;
34 + }
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");
38 }
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
42 @@ -31,7 +31,7 @@
43 #include "autoconf.h"
44
45 #include "gdbmdefs.h"
46 -
47 +#include <errno.h>
48
49 /* The forward definitions for this file. See the functions for
50 the definition of the function. */
51 @@ -174,7 +174,8 @@
52 pop_avail_block (dbf)
53 gdbm_file_info *dbf;
54 {
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. */
59 avail_elem new_el;
60 avail_block *new_blk;
61 @@ -199,7 +200,12 @@
62 /* Read the block. */
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);
66 + do
67 + {
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;
70 + }
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");
73
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
78 @@ -31,6 +31,7 @@
79 #include "autoconf.h"
80
81 #include "gdbmdefs.h"
82 +#include <errno.h>
83
84
85 /* Read the data found in bucket entry ELEM_LOC in file DBF and
86 @@ -41,11 +42,12 @@
87 gdbm_file_info *dbf;
88 int elem_loc;
89 {
90 - int num_bytes; /* For seeking and reading. */
91 + int num_bytes = 0; /* For seeking and reading. */
92 int key_size;
93 int data_size;
94 off_t file_pos;
95 data_cache_elem *data_ca;
96 + int bytes_read;
97
98 /* Is it already in the cache? */
99 if (dbf->cache_entry->ca_data.elem_loc == elem_loc)
100 @@ -74,7 +76,12 @@
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);
105 + do
106 + {
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;
109 + }
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");
112
113 return data_ca->dptr;