diff options
author | Stefan Metzmacher <metze@samba.org> | 2013-05-28 12:56:57 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2013-06-03 10:21:22 +0200 |
commit | a07ba17e0c91d726416db946e6f65b064b2d17ec (patch) | |
tree | e603eb5d0c179f3a3837bcdec2ac3a7421bbef4b /lib/tdb | |
parent | 4483bf143ddfee9ec07aed8f124559b00f757d9a (diff) | |
download | samba-a07ba17e0c91d726416db946e6f65b064b2d17ec.tar.gz |
tdb: add a 'new_size' helper variable to tdb_expand_file()
Pair-Programmed-With: Volker Lendecke <vl@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/tdb')
-rw-r--r-- | lib/tdb/common/io.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/tdb/common/io.c b/lib/tdb/common/io.c index a477fb55e4..44ef7289a6 100644 --- a/lib/tdb/common/io.c +++ b/lib/tdb/common/io.c @@ -287,18 +287,21 @@ int tdb_mmap(struct tdb_context *tdb) static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t addition) { char buf[8192]; + tdb_off_t new_size; if (tdb->read_only || tdb->traverse_read) { tdb->ecode = TDB_ERR_RDONLY; return -1; } - if (ftruncate(tdb->fd, size+addition) == -1) { + new_size = size + addition; + + if (ftruncate(tdb->fd, new_size) == -1) { char b = 0; - ssize_t written = pwrite(tdb->fd, &b, 1, (size+addition) - 1); + ssize_t written = pwrite(tdb->fd, &b, 1, new_size - 1); if (written == 0) { /* try once more, potentially revealing errno */ - written = pwrite(tdb->fd, &b, 1, (size+addition) - 1); + written = pwrite(tdb->fd, &b, 1, new_size - 1); } if (written == 0) { /* again - give up, guessing errno */ @@ -306,7 +309,7 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad } if (written != 1) { TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file to %u failed (%s)\n", - size+addition, strerror(errno))); + (unsigned)new_size, strerror(errno))); return -1; } } |