/ Check-in [7d67d876]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the build for cases when pread()/pwrite() are not available.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | pread
Files: files | file ages | folders
SHA1: 7d67d876b70c7a4199697c5b112d809c600e140e
User & Date: drh 2016-03-04 03:02:06
Context
2016-03-04
03:14
Further fixes to the pread()/pwrite() enabling logic. Closed-Leaf check-in: 38fb54e7 user: drh tags: pread
03:02
Fix the build for cases when pread()/pwrite() are not available. check-in: 7d67d876 user: drh tags: pread
02:38
Update the configure script to detect pread/pwrite and update os_unix.c to use those routines if they are available. check-in: 2cffb9e5 user: drh tags: pread
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

    80     80   #elif defined(HAVE_PREAD) && defined(HAVE_PWRITE)
    81     81   # undef USE_PREAD
    82     82   # undef USE_PWRITE
    83     83   # define USE_PREAD64 1
    84     84   # define USE_PWRITE64 1
    85     85   #endif
    86     86   
    87         -
    88     87   /*
    89     88   ** standard include files.
    90     89   */
    91     90   #include <sys/types.h>
    92     91   #include <sys/stat.h>
    93     92   #include <fcntl.h>
    94     93   #include <unistd.h>
................................................................................
   210    209     unsigned short int ctrlFlags;       /* Behavioral bits.  UNIXFILE_* flags */
   211    210     int lastErrno;                      /* The unix errno from last I/O error */
   212    211     void *lockingContext;               /* Locking style specific state */
   213    212     UnixUnusedFd *pUnused;              /* Pre-allocated UnixUnusedFd */
   214    213     const char *zPath;                  /* Name of the file */
   215    214     unixShm *pShm;                      /* Shared memory segment information */
   216    215     int szChunk;                        /* Configured by FCNTL_CHUNK_SIZE */
   217         -#if !defined(USE_PREAD) && !defined(USE_PREAD64)
   218         -  off64_t iOfst;                      /* Current offset */
   219         -#endif
   220    216   #if SQLITE_MAX_MMAP_SIZE>0
   221    217     int nFetchOut;                      /* Number of outstanding xFetch refs */
   222    218     sqlite3_int64 mmapSize;             /* Usable size of mapping at pMapRegion */
   223    219     sqlite3_int64 mmapSizeActual;       /* Actual size of mapping at pMapRegion */
   224    220     sqlite3_int64 mmapSizeMax;          /* Configured FCNTL_MMAP_SIZE value */
   225    221     void *pMapRegion;                   /* Memory mapped region */
   226    222   #endif
................................................................................
  3110   3106   **
  3111   3107   ** To avoid stomping the errno value on a failed read the lastErrno value
  3112   3108   ** is set before returning.
  3113   3109   */
  3114   3110   static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
  3115   3111     int got;
  3116   3112     int prior = 0;
         3113  +#if (!defined(USE_PREAD) && !defined(USE_PREAD64))
         3114  +  i64 newOffset;
         3115  +#endif
  3117   3116     TIMER_START;
  3118   3117     assert( cnt==(cnt&0x1ffff) );
  3119   3118     assert( id->h>2 );
  3120   3119     do{
  3121   3120   #if defined(USE_PREAD)
  3122   3121       got = osPread(id->h, pBuf, cnt, offset);
  3123   3122       SimulateIOError( got = -1 );
  3124   3123   #elif defined(USE_PREAD64)
  3125   3124       got = osPread64(id->h, pBuf, cnt, offset);
  3126   3125       SimulateIOError( got = -1 );
  3127   3126   #else
  3128         -    if( offset!=id->iOfst ){
  3129         -      id->iOfst = lseek(id->h, offset, SEEK_SET);
  3130         -      SimulateIOError( id->iOfst = -1 );
  3131         -      if( id->iOfst<0 ){
  3132         -        storeLastErrno((unixFile*)id, errno);
  3133         -        return -1;
  3134         -      }
  3135         -      got = osRead(id->h, pBuf, cnt);
  3136         -      if( got>=0 ) id->iOfst += got;
         3127  +    newOffset = lseek(id->h, offset, SEEK_SET);
         3128  +    SimulateIOError( newOffset = -1 );
         3129  +    if( newOffset<0 ){
         3130  +      storeLastErrno((unixFile*)id, errno);
         3131  +      return -1;
         3132  +    }
         3133  +    got = osRead(id->h, pBuf, cnt);
  3137   3134   #endif
  3138   3135       if( got==cnt ) break;
  3139   3136       if( got<0 ){
  3140   3137         if( errno==EINTR ){ got = 1; continue; }
  3141   3138         prior = 0;
  3142   3139         storeLastErrno((unixFile*)id,  errno);
  3143   3140         break;
................................................................................
  3235   3232   
  3236   3233   #if defined(USE_PREAD)
  3237   3234     do{ rc = (int)osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR );
  3238   3235   #elif defined(USE_PREAD64)
  3239   3236     do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
  3240   3237   #else
  3241   3238     do{
  3242         -    if( iOff!=fd
  3243   3239       i64 iSeek = lseek(fd, iOff, SEEK_SET);
  3244   3240       SimulateIOError( iSeek = -1 );
  3245   3241       if( iSeek<0 ){
  3246   3242         rc = -1;
  3247   3243         break;
  3248   3244       }
  3249   3245       rc = osWrite(fd, pBuf, nBuf);