VFS xTruncate implementation

This commit is contained in:
Sandrine Avakian 2017-02-28 13:50:14 +01:00
parent 17df3b86a5
commit a356548df1

View file

@ -115,6 +115,28 @@ static int sqlite3bctbx_Write(sqlite3_file *p, const void *buf, int count, sqlit
return SQLITE_IOERR_WRITE;
}
/**
* TRuncates or extends a file depending on the size provided.
* @param p sqlite3_file file handle pointer.
* @param size New file size.
* @return SQLITE_OK on success, SQLITE_IOERR_TRUNCATE if an error occurred during truncate,
* SQLITE_ERROR if ther was a problem on the file descriptor.
*/
static int sqlite3bctbx_Truncate(sqlite3_file *p, sqlite_int64 size){
int rc;
sqlite3_bctbx_file_t *pFile = (sqlite3_bctbx_file_t*) p;
if (pFile->pbctbx_file){
rc = bctbx_file_truncate(pFile->pbctbx_file, size);
if( rc < 0 ) {
return SQLITE_IOERR_TRUNCATE;
}
if (rc == 0){
return SQLITE_OK;
}
}
return SQLITE_ERROR;
}
/**
* Saves the file size associated with the file handle p into the argument pSize.
@ -304,7 +326,7 @@ static int sqlite3bctbx_Open(sqlite3_vfs *pVfs, const char *fName, sqlite3_file
sqlite3bctbx_Close, /* xClose */
sqlite3bctbx_Read, /* xRead */
sqlite3bctbx_Write, /* xWrite */
NULL, /* xTruncate */
sqlite3bctbx_Truncate, /* xTruncate */
sqlite3bctbx_Sync,
sqlite3bctbx_FileSize,
sqlite3bctbx_nolockLock,