From 0ef1acbabb13006429d06cb1d90bf887bf987ddc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 19 Sep 2001 06:55:25 +0000 Subject: Put pwrite code back in expand_file. Jeremy. (This used to be commit a3267551d88dffb226e4a1c3852fe9c817517d02) --- source3/tdb/tdb.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c index 3a5b66bbc7..b90c307ec6 100644 --- a/source3/tdb/tdb.c +++ b/source3/tdb/tdb.c @@ -611,24 +611,31 @@ static int expand_file(TDB_CONTEXT *tdb, tdb_off size, tdb_off addition) #else char b = 0; +#ifdef HAVE_PWRITE + if (pwrite(tdb->fd, &b, 1, (size+addition) - 1) != 1) { +#else if (lseek(tdb->fd, (size+addition) - 1, SEEK_SET) != (size+addition) - 1 || write(tdb->fd, &b, 1) != 1) { +#endif TDB_LOG((tdb, 0, "expand_file to %d failed (%s)\n", size+addition, strerror(errno))); return -1; } #endif - /* now fill the file with something. This ensures that the - file isn't sparse, which would be very bad if we ran out of - disk. This must be done with write, not via mmap */ + /* now fill the file with something. This ensures that the file isn't sparse, which would be + very bad if we ran out of disk. This must be done with write, not via mmap */ memset(buf, 0x42, sizeof(buf)); while (addition) { int n = addition>sizeof(buf)?sizeof(buf):addition; +#ifdef HAVE_PWRITE + int ret = pwrite(tdb->fd, buf, n, size); +#else int ret; if (lseek(tdb->fd, size, SEEK_SET) != size) return -1; ret = write(tdb->fd, buf, n); +#endif if (ret != n) { TDB_LOG((tdb, 0, "expand_file write of %d failed (%s)\n", n, strerror(errno))); -- cgit