diff options
author | drh <drh@noemail.net> | 2015-12-01 22:09:42 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2015-12-01 22:09:42 +0000 |
commit | 053378dfa82c7e03f76dd78d5968ea43b0b1cce5 (patch) | |
tree | fc9a9d658528ba605975be1b5b688313425b0be6 /src/os_unix.c | |
parent | 41d2e66ef3de25a0d78a79bfbb781f305842c77b (diff) | |
download | sqlite-053378dfa82c7e03f76dd78d5968ea43b0b1cce5.tar.gz sqlite-053378dfa82c7e03f76dd78d5968ea43b0b1cce5.zip |
Simplification to the posix_fallocate() replacement used for the
SQLITE_FCNTL_SIZE_HINT file control in the unix VFS.
FossilOrigin-Name: 74934d3f60ad9f6550297410eada0f288e0123c4
Diffstat (limited to 'src/os_unix.c')
-rw-r--r-- | src/os_unix.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/os_unix.c b/src/os_unix.c index 475beed28..e3a6f778d 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3662,18 +3662,14 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){ int nWrite = 0; /* Number of bytes written by seekAndWrite */ i64 iWrite; /* Next offset to write to */ - iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1; + iWrite = (buf.st_size/nBlk)*nBlk + nBlk - 1; assert( iWrite>=buf.st_size ); - assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) ); assert( ((iWrite+1)%nBlk)==0 ); - for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){ + for(/*no-op*/; iWrite<nSize+nBlk-1; iWrite+=nBlk ){ + if( iWrite>=nSize ) iWrite = nSize - 1; nWrite = seekAndWrite(pFile, iWrite, "", 1); if( nWrite!=1 ) return SQLITE_IOERR_WRITE; } - if( nWrite==0 || (nSize%nBlk) ){ - nWrite = seekAndWrite(pFile, nSize-1, "", 1); - if( nWrite!=1 ) return SQLITE_IOERR_WRITE; - } #endif } } |