From a07ba17e0c91d726416db946e6f65b064b2d17ec Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 28 May 2013 12:56:57 +0200 Subject: tdb: add a 'new_size' helper variable to tdb_expand_file() Pair-Programmed-With: Volker Lendecke Signed-off-by: Stefan Metzmacher Signed-off-by: Volker Lendecke Reviewed-by: Rusty Russell --- lib/tdb/common/io.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/tdb/common') 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; } } -- cgit