From e32a256acd23dcde4671a662426afa8a6d3a354b Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 4 Mar 2016 02:38:00 +0000 Subject: [PATCH] Update the configure script to detect pread/pwrite and update os_unix.c to use those routines if they are available. FossilOrigin-Name: 2cffb9e50bed77d1079603f5b4a71b7559de7294 --- config.h.in | 12 ++++++++++++ configure | 2 +- configure.ac | 2 +- manifest | 19 +++++++++---------- manifest.uuid | 2 +- src/os_unix.c | 37 +++++++++++++++++++++++++++---------- 6 files changed, 51 insertions(+), 23 deletions(-) diff --git a/config.h.in b/config.h.in index 36fd60781c..f2ba7d4fc4 100644 --- a/config.h.in +++ b/config.h.in @@ -45,6 +45,18 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H +/* Define to 1 if you have the pread() function. */ +#undef HAVE_PREAD + +/* Define to 1 if you have the pread64() function. */ +#undef HAVE_PREAD64 + +/* Define to 1 if you have the pwrite() function. */ +#undef HAVE_PWRITE + +/* Define to 1 if you have the pwrite64() function. */ +#undef HAVE_PWRITE64 + /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H diff --git a/configure b/configure index 09fba81eae..8363818c6f 100755 --- a/configure +++ b/configure @@ -10273,7 +10273,7 @@ done ######### # Figure out whether or not we have these functions # -for ac_func in fdatasync gmtime_r isnan localtime_r localtime_s malloc_usable_size strchrnul usleep utime +for ac_func in fdatasync gmtime_r isnan localtime_r localtime_s malloc_usable_size strchrnul usleep utime pread pread64 pwrite pwrite64 do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.ac b/configure.ac index 19f85dc875..08c8867f06 100644 --- a/configure.ac +++ b/configure.ac @@ -108,7 +108,7 @@ AC_CHECK_HEADERS([sys/types.h stdlib.h stdint.h inttypes.h malloc.h]) ######### # Figure out whether or not we have these functions # -AC_CHECK_FUNCS([fdatasync gmtime_r isnan localtime_r localtime_s malloc_usable_size strchrnul usleep utime]) +AC_CHECK_FUNCS([fdatasync gmtime_r isnan localtime_r localtime_s malloc_usable_size strchrnul usleep utime pread pread64 pwrite pwrite64]) ######### # By default, we use the amalgamation (this may be changed below...) diff --git a/manifest b/manifest index 7f70989146..06e5c8c969 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reduce\sthe\samount\sof\sheap\smemory\srequired\sto\sstore\smany\sschemas\sby\sstoring\s\nthe\scolumn\sdatatype\sappended\sto\sthe\scolumn\sname\s(with\sa\s\\000\sseparator),\s\nrather\sthan\sin\sseparate\smemory\sallocation. -D 2016-03-03T21:22:53.735 +C Update\sthe\sconfigure\sscript\sto\sdetect\spread/pwrite\sand\supdate\sos_unix.c\sto\nuse\sthose\sroutines\sif\sthey\sare\savailable. +D 2016-03-04T02:38:00.565 F Makefile.in e335453db0b16da00c884ad51bb56d1c091a74de F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc dbd4621ecc585c2ef0c2aa0874698c54675754f1 @@ -28,10 +28,10 @@ F autoconf/tea/win/makefile.vc f89d0184d0eee5f7e356ea407964dcd139939928 F autoconf/tea/win/nmakehlp.c 247538ad8e8c508f33c03ec1fbd67d3a07ef6291 F autoconf/tea/win/rules.vc c511f222b80064096b705dbeb97060ee1d6b6d63 F config.guess 226d9a188c6196f3033ffc651cbc9dcee1a42977 -F config.h.in 42b71ad3fe21c9e88fa59e8458ca1a6bc72eb0c0 +F config.h.in 6376abec766e9a0785178b1823b5a587e9f1ccbc F config.sub 9ebe4c3b3dab6431ece34f16828b594fb420da55 -F configure 0339a635cd2943a3b56000a10a11b4b2e6ed6d1b x -F configure.ac a2224b1162f79848982d3618ac1deffcd94e88ec +F configure c01a159fdf7ea0171ad01ce2937283f2c7972bde x +F configure.ac 89e4e02a83d8a1528011f8395621b8c3186b4089 F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad F doc/lemon.html c30255bea0fd87a81f082d17a72c9dffbc3f6dd9 F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710 @@ -333,7 +333,7 @@ F src/os.c ca9a104b677328ee037cfdf1a54a16fd1805e8c9 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c 3a6f20736dfb8a0949cdd66553fdf59f6604be35 +F src/os_unix.c a1aaf2d8d253138e63d2a8a972693f9f624f885d F src/os_win.c f0d7aa603eb6262143d7169a222aea07c4fca91d F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c d034c69b958c01289eb8070cbf902e1a68cd7e0b @@ -1453,8 +1453,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3eb74342740cd393e03aa38cd01690ccab173b76 842b21162713bb141b845b01c136457a31af4ab0 -R 8594cd13d54710bae620a17d4ba5114b -T +closed 842b21162713bb141b845b01c136457a31af4ab0 +P 16fbf2e19c22df9441aef5c8b7f5670adc38a6b6 +R 8390ec5e0d9e5eb3999e5eee0cb5ce81 U drh -Z 4f9819dace7a151b6043885dfe386959 +Z b764ac5f33b779f6bf5d09a763220c12 diff --git a/manifest.uuid b/manifest.uuid index 82610772e0..ec9225526f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -16fbf2e19c22df9441aef5c8b7f5670adc38a6b6 \ No newline at end of file +2cffb9e50bed77d1079603f5b4a71b7559de7294 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index ea07bd99f3..9bcefb1195 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 ){