aboutsummaryrefslogtreecommitdiff
path: root/src/gdbmopen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gdbmopen.c')
-rw-r--r--src/gdbmopen.c29
1 files changed, 26 insertions, 3 deletions
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 }

Return to:

Send suggestions and report system problems to the System administrator.