summaryrefslogtreecommitdiffabout
path: root/src/mmap.c
Unidiff
Diffstat (limited to 'src/mmap.c') (more/less context) (show whitespace changes)
-rw-r--r--src/mmap.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/mmap.c b/src/mmap.c
index 114d8b2..24ede29 100644
--- a/src/mmap.c
+++ b/src/mmap.c
@@ -41,14 +41,21 @@
41 ((off) >= (dbf)->mapped_off \ 41 ((off) >= (dbf)->mapped_off \
42 && ((off) - (dbf)->mapped_off) < (dbf)->mapped_size) 42 && ((off) - (dbf)->mapped_off) < (dbf)->mapped_size)
43/* Return true if the current region needs to be remapped */ 43/* Return true if the current region needs to be remapped */
44# define _GDBM_NEED_REMAP(dbf) \ 44# define _GDBM_NEED_REMAP(dbf) \
45 (!(dbf)->mapped_region || (dbf)->mapped_pos == (dbf)->mapped_size) 45 (!(dbf)->mapped_region || (dbf)->mapped_pos == (dbf)->mapped_size)
46/* Return the sum of the currently mapped size and DELTA */ 46/* Return the sum of the currently mapped size and DELTA */
47# define SUM_FILE_SIZE(dbf, delta) \ 47static inline off_t
48 ((dbf)->mapped_off + (dbf)->mapped_size + (delta)) 48SUM_FILE_SIZE (GDBM_FILE dbf, off_t delta)
49{
50 if (delta >= 0
51 && off_t_sum_ok (dbf->mapped_off, dbf->mapped_size)
52 && off_t_sum_ok (dbf->mapped_off + dbf->mapped_size, delta))
53 return dbf->mapped_off + dbf->mapped_size + delta;
54 return -1;
55}
49 56
50/* Store the size of the GDBM file DBF in *PSIZE. 57/* Store the size of the GDBM file DBF in *PSIZE.
51 Return 0 on success and -1 on failure. */ 58 Return 0 on success and -1 on failure. */
52int 59int
53_gdbm_file_size (GDBM_FILE dbf, off_t *psize) 60_gdbm_file_size (GDBM_FILE dbf, off_t *psize)
54{ 61{
@@ -179,12 +186,23 @@ _gdbm_file_extend (GDBM_FILE dbf, off_t size)
179 The function returns 0 on success, -1 on failure. */ 186 The function returns 0 on success, -1 on failure. */
180int 187int
181_gdbm_mapped_remap (GDBM_FILE dbf, off_t size, int flag) 188_gdbm_mapped_remap (GDBM_FILE dbf, off_t size, int flag)
182{ 189{
183 off_t file_size, pos; 190 off_t file_size, pos;
184 191
192 if (size < 0)
193 {
194 errno = EINVAL;
195 GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE);
196 return -1;
197 }
198
199 if (size < dbf->mapped_size)
200 /* Nothing to do */
201 return 0;
202
185 if (_gdbm_file_size (dbf, &file_size)) 203 if (_gdbm_file_size (dbf, &file_size))
186 { 204 {
187 SAVE_ERRNO (_gdbm_mapped_unmap (dbf)); 205 SAVE_ERRNO (_gdbm_mapped_unmap (dbf));
188 return -1; 206 return -1;
189 } 207 }
190 208

Return to:

Send suggestions and report system problems to the System administrator.