aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/falloc.c54
-rw-r--r--src/gdbm.h.in3
-rw-r--r--src/gdbmdump.c2
-rw-r--r--src/gdbmerrno.c6
-rw-r--r--src/gdbmload.c1
-rw-r--r--src/gdbmopen.c29
-rw-r--r--src/gdbmseq.c1
-rw-r--r--src/gdbmtool.c2
-rw-r--r--src/mmap.c4
-rw-r--r--src/systems.h7
-rw-r--r--src/util.c5
11 files changed, 75 insertions, 39 deletions
diff --git a/src/falloc.c b/src/falloc.c
index 09b40d4..7a94afb 100644
--- a/src/falloc.c
+++ b/src/falloc.c
@@ -313,33 +313,43 @@ push_avail_block (GDBM_FILE dbf)
313 /* Update the header avail count to previous size divided by 2. */ 313 /* Update the header avail count to previous size divided by 2. */
314 dbf->header->avail.count >>= 1; 314 dbf->header->avail.count >>= 1;
315 315
316 /* Free the unneeded space. */ 316 rc = 0;
317 new_loc.av_adr += av_size; 317 do
318 new_loc.av_size -= av_size;
319 _gdbm_free (dbf, new_loc.av_adr, new_loc.av_size);
320
321 /* Update the disk. */
322 file_pos = gdbm_file_seek (dbf, av_adr, SEEK_SET);
323 if (file_pos != av_adr)
324 { 318 {
325 GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE); 319 /* Free the unneeded space. */
326 _gdbm_fatal (dbf, _("lseek error")); 320 new_loc.av_adr += av_size;
327 return -1; 321 new_loc.av_size -= av_size;
328 } 322 if (_gdbm_free (dbf, new_loc.av_adr, new_loc.av_size))
323 {
324 rc = -1;
325 break;
326 }
327
328 /* Update the disk. */
329 file_pos = gdbm_file_seek (dbf, av_adr, SEEK_SET);
330 if (file_pos != av_adr)
331 {
332 GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE);
333 _gdbm_fatal (dbf, _("lseek error"));
334 rc = -1;
335 break;
336 }
329 337
330 rc = _gdbm_full_write (dbf, temp, av_size); 338 rc = _gdbm_full_write (dbf, temp, av_size);
331 if (rc) 339 if (rc)
332 { 340 {
333 GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR, 341 GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR,
334 "%s: error writing avail data: %s", 342 "%s: error writing avail data: %s",
335 dbf->name, gdbm_db_strerror (dbf)); 343 dbf->name, gdbm_db_strerror (dbf));
336 _gdbm_fatal (dbf, gdbm_db_strerror (dbf)); 344 _gdbm_fatal (dbf, gdbm_db_strerror (dbf));
337 return -1; 345 rc = -1;
346 }
338 } 347 }
339 348 while (0);
349
340 free (temp); 350 free (temp);
341 351
342 return 0; 352 return rc;
343} 353}
344 354
345/* AV_TABLE contains COUNT entries sorted by AV_SIZE in ascending order. 355/* AV_TABLE contains COUNT entries sorted by AV_SIZE in ascending order.
diff --git a/src/gdbm.h.in b/src/gdbm.h.in
index 6318ad8..f5eadc5 100644
--- a/src/gdbm.h.in
+++ b/src/gdbm.h.in
@@ -227,9 +227,10 @@ extern int gdbm_copy_meta (GDBM_FILE dst, GDBM_FILE src);
227# define GDBM_BAD_DIR_ENTRY 36 227# define GDBM_BAD_DIR_ENTRY 36
228# define GDBM_FILE_CLOSE_ERROR 37 228# define GDBM_FILE_CLOSE_ERROR 37
229# define GDBM_FILE_SYNC_ERROR 38 229# define GDBM_FILE_SYNC_ERROR 38
230# define GDBM_FILE_TRUNCATE_ERROR 39
230 231
231# define _GDBM_MIN_ERRNO 0 232# define _GDBM_MIN_ERRNO 0
232# define _GDBM_MAX_ERRNO GDBM_FILE_SYNC_ERROR 233# define _GDBM_MAX_ERRNO GDBM_FILE_TRUNCATE_ERROR
233 234
234/* This one was never used and will be removed in the future */ 235/* This one was never used and will be removed in the future */
235# define GDBM_UNKNOWN_UPDATE GDBM_UNKNOWN_ERROR 236# define GDBM_UNKNOWN_UPDATE GDBM_UNKNOWN_ERROR
diff --git a/src/gdbmdump.c b/src/gdbmdump.c
index 2e6f5b0..a8c4ec5 100644
--- a/src/gdbmdump.c
+++ b/src/gdbmdump.c
@@ -62,7 +62,7 @@ _gdbm_dump_ascii (GDBM_FILE dbf, FILE *fp)
62 size_t count = 0; 62 size_t count = 0;
63 unsigned char *buffer = NULL; 63 unsigned char *buffer = NULL;
64 size_t bufsize = 0; 64 size_t bufsize = 0;
65 int rc; 65 int rc = 0;
66 66
67 fd = gdbm_fdesc (dbf); 67 fd = gdbm_fdesc (dbf);
68 if (fstat (fd, &st)) 68 if (fstat (fd, &st))
diff --git a/src/gdbmerrno.c b/src/gdbmerrno.c
index 4ce7f9d..6758272 100644
--- a/src/gdbmerrno.c
+++ b/src/gdbmerrno.c
@@ -138,7 +138,8 @@ const char * const gdbm_errlist[_GDBM_MAX_ERRNO+1] = {
138 [GDBM_BAD_HASH_TABLE] = N_("Malformed hash table"), 138 [GDBM_BAD_HASH_TABLE] = N_("Malformed hash table"),
139 [GDBM_BAD_DIR_ENTRY] = N_("Invalid directory entry"), 139 [GDBM_BAD_DIR_ENTRY] = N_("Invalid directory entry"),
140 [GDBM_FILE_CLOSE_ERROR] = N_("Error closing file"), 140 [GDBM_FILE_CLOSE_ERROR] = N_("Error closing file"),
141 [GDBM_FILE_SYNC_ERROR] = N_("Error synchronizing file") 141 [GDBM_FILE_SYNC_ERROR] = N_("Error synchronizing file"),
142 [GDBM_FILE_TRUNCATE_ERROR] = N_("Error truncating file")
142}; 143};
143 144
144const char * 145const char *
@@ -182,7 +183,8 @@ int const gdbm_syserr[_GDBM_MAX_ERRNO+1] = {
182 [GDBM_FILE_STAT_ERROR] = 1, 183 [GDBM_FILE_STAT_ERROR] = 1,
183 [GDBM_BACKUP_FAILED] = 1, 184 [GDBM_BACKUP_FAILED] = 1,
184 [GDBM_FILE_CLOSE_ERROR] = 1, 185 [GDBM_FILE_CLOSE_ERROR] = 1,
185 [GDBM_FILE_SYNC_ERROR] = 1 186 [GDBM_FILE_SYNC_ERROR] = 1,
187 [GDBM_FILE_TRUNCATE_ERROR] = 1
186}; 188};
187 189
188/* Returns true if system errno value is meaningful for GDBM error 190/* Returns true if system errno value is meaningful for GDBM error
diff --git a/src/gdbmload.c b/src/gdbmload.c
index 008bcb9..f5b7869 100644
--- a/src/gdbmload.c
+++ b/src/gdbmload.c
@@ -542,6 +542,7 @@ gdbm_load_bdb_dump (struct dump_file *file, GDBM_FILE dbf, int replace)
542 memset (&xd, 0, sizeof (xd)); 542 memset (&xd, 0, sizeof (xd));
543 xs[0] = xs[1] = 0; 543 xs[0] = xs[1] = 0;
544 i = 0; 544 i = 0;
545 rc = 0;
545 while ((c = fgetc (file->fp)) == ' ') 546 while ((c = fgetc (file->fp)) == ' ')
546 { 547 {
547 rc = xdatum_read (file->fp, &xd[i], &xs[i]); 548 rc = xdatum_read (file->fp, &xd[i], &xs[i]);
diff --git a/src/gdbmopen.c b/src/gdbmopen.c
index 908887c..7ec57e7 100644
--- a/src/gdbmopen.c
+++ b/src/gdbmopen.c
@@ -199,6 +199,21 @@ validate_header (gdbm_file_header const *hdr, struct stat const *st)
199 return 0; 199 return 0;
200} 200}
201 201
202/* Do we have ftruncate? */
203static inline int
204_gdbm_ftruncate (GDBM_FILE dbf)
205{
206#if HAVE_FTRUNCATE
207 return ftruncate (dbf->desc, 0);
208#else
209 int fd;
210 fd = open (dbf->name, O_RDWR|O_TRUNC, mode);
211 if (fd == -1)
212 return -1;
213 return close (fd);
214#endif
215}
216
202GDBM_FILE 217GDBM_FILE
203gdbm_fd_open (int fd, const char *file_name, int block_size, 218gdbm_fd_open (int fd, const char *file_name, int block_size,
204 int flags, void (*fatal_func) (const char *)) 219 int flags, void (*fatal_func) (const char *))
@@ -320,14 +335,22 @@ gdbm_fd_open (int fd, const char *file_name, int block_size,
320 now time to truncate the file. */ 335 now time to truncate the file. */
321 if ((flags & GDBM_OPENMASK) == GDBM_NEWDB && file_stat.st_size != 0) 336 if ((flags & GDBM_OPENMASK) == GDBM_NEWDB && file_stat.st_size != 0)
322 { 337 {
323 TRUNCATE (dbf); 338 if (_gdbm_ftruncate (dbf))
324 if (fstat (dbf->desc, &file_stat)) 339 {
340 GDBM_SET_ERRNO2 (dbf, GDBM_FILE_TRUNCATE_ERROR, FALSE,
341 GDBM_DEBUG_OPEN);
342 }
343 else if (fstat (dbf->desc, &file_stat))
344 {
345 GDBM_SET_ERRNO2 (dbf, GDBM_FILE_STAT_ERROR, FALSE, GDBM_DEBUG_OPEN);
346 }
347
348 if (gdbm_last_errno (dbf))
325 { 349 {
326 if (flags & GDBM_CLOERROR) 350 if (flags & GDBM_CLOERROR)
327 close (dbf->desc); 351 close (dbf->desc);
328 free (dbf->name); 352 free (dbf->name);
329 free (dbf); 353 free (dbf);
330 GDBM_SET_ERRNO2 (NULL, GDBM_FILE_STAT_ERROR, FALSE, GDBM_DEBUG_OPEN);
331 return NULL; 354 return NULL;
332 } 355 }
333 } 356 }
diff --git a/src/gdbmseq.c b/src/gdbmseq.c
index e74d78d..ee7ebf3 100644
--- a/src/gdbmseq.c
+++ b/src/gdbmseq.c
@@ -101,6 +101,7 @@ gdbm_firstkey (GDBM_FILE dbf)
101 101
102 /* Set the default return value for not finding a first entry. */ 102 /* Set the default return value for not finding a first entry. */
103 return_val.dptr = NULL; 103 return_val.dptr = NULL;
104 return_val.dsize = 0;
104 105
105 GDBM_DEBUG (GDBM_DEBUG_READ, "%s: getting first key", dbf->name); 106 GDBM_DEBUG (GDBM_DEBUG_READ, "%s: getting first key", dbf->name);
106 107
diff --git a/src/gdbmtool.c b/src/gdbmtool.c
index 454465e..8c97e1e 100644
--- a/src/gdbmtool.c
+++ b/src/gdbmtool.c
@@ -1435,7 +1435,7 @@ command_generator (const char *text, int state)
1435 len = strlen (text); 1435 len = strlen (text);
1436 } 1436 }
1437 1437
1438 if (!cmd->name) 1438 if (!cmd || !cmd->name)
1439 return NULL; 1439 return NULL;
1440 1440
1441 /* Return the next name which partially matches from the command list. */ 1441 /* Return the next name which partially matches from the command list. */
diff --git a/src/mmap.c b/src/mmap.c
index 48e84ae..148b852 100644
--- a/src/mmap.c
+++ b/src/mmap.c
@@ -367,6 +367,10 @@ _gdbm_mapped_lseek (GDBM_FILE dbf, off_t offset, int whence)
367 needle = file_size - offset; 367 needle = file_size - offset;
368 break; 368 break;
369 } 369 }
370
371 default:
372 errno = EINVAL;
373 return -1;
370 } 374 }
371