aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index ea07bd99f..9bcefb119 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -71,6 +71,20 @@
# endif
#endif
+/* Use pread() and pwrite() if they are available */
+#if defined(HAVE_PREAD64) && defined(HAVE_PWRITE64)
+# undef USE_PREAD
+# undef USE_PWRITE
+# define USE_PREAD64 1
+# define USE_PWRITE64 1
+#elif defined(HAVE_PREAD) && defined(HAVE_PWRITE)
+# undef USE_PREAD
+# undef USE_PWRITE
+# define USE_PREAD64 1
+# define USE_PWRITE64 1
+#endif
+
+
/*
** standard include files.
*/
@@ -200,6 +214,9 @@ struct unixFile {
const char *zPath; /* Name of the file */
unixShm *pShm; /* Shared memory segment information */
int szChunk; /* Configured by FCNTL_CHUNK_SIZE */
+#if !defined(USE_PREAD) && !defined(USE_PREAD64)
+ off64_t iOfst; /* Current offset */
+#endif
#if SQLITE_MAX_MMAP_SIZE>0
int nFetchOut; /* Number of outstanding xFetch refs */
sqlite3_int64 mmapSize; /* Usable size of mapping at pMapRegion */
@@ -3097,9 +3114,6 @@ static int nfsUnlock(sqlite3_file *id, int eFileLock){
static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
int got;
int prior = 0;
-#if (!defined(USE_PREAD) && !defined(USE_PREAD64))
- i64 newOffset;
-#endif
TIMER_START;
assert( cnt==(cnt&0x1ffff) );
assert( id->h>2 );
@@ -3111,13 +3125,15 @@ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
got = osPread64(id->h, pBuf, cnt, offset);
SimulateIOError( got = -1 );
#else
- newOffset = lseek(id->h, offset, SEEK_SET);
- SimulateIOError( newOffset = -1 );
- if( newOffset<0 ){
- storeLastErrno((unixFile*)id, errno);
- return -1;
- }
- got = osRead(id->h, pBuf, cnt);
+ if( offset!=id->iOfst ){
+ id->iOfst = lseek(id->h, offset, SEEK_SET);
+ SimulateIOError( id->iOfst = -1 );
+ if( id->iOfst<0 ){
+ storeLastErrno((unixFile*)id, errno);
+ return -1;
+ }
+ got = osRead(id->h, pBuf, cnt);
+ if( got>=0 ) id->iOfst += got;
#endif
if( got==cnt ) break;
if( got<0 ){
@@ -3223,6 +3239,7 @@ static int seekAndWriteFd(
do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
#else
do{
+ if( iOff!=fd
i64 iSeek = lseek(fd, iOff, SEEK_SET);
SimulateIOError( iSeek = -1 );
if( iSeek<0 ){