diff options
author | drh <drh@noemail.net> | 2004-10-01 02:00:31 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2004-10-01 02:00:31 +0000 |
commit | eb206256f1fac9b79fde3375f3670c5ecb52f11b (patch) | |
tree | 88fdcce79a1ac7d3c59620c4222e094397c6d20c /src | |
parent | a3f70cbc313f245c53696a08c1d27fdbcd41df97 (diff) | |
download | sqlite-eb206256f1fac9b79fde3375f3670c5ecb52f11b.tar.gz sqlite-eb206256f1fac9b79fde3375f3670c5ecb52f11b.zip |
Use type i64 instead of off_t for file offsets since off_t is giving
portability problems. Ticket #924. (CVS 1992)
FossilOrigin-Name: 8972c004dc825f668d952e7d082a89046b9260f1
Diffstat (limited to 'src')
-rw-r--r-- | src/date.c | 4 | ||||
-rw-r--r-- | src/os.h | 6 | ||||
-rw-r--r-- | src/os_mac.c | 4 | ||||
-rw-r--r-- | src/os_mac.h | 5 | ||||
-rw-r--r-- | src/os_test.c | 22 | ||||
-rw-r--r-- | src/os_unix.c | 11 | ||||
-rw-r--r-- | src/os_win.c | 12 | ||||
-rw-r--r-- | src/os_win.h | 11 | ||||
-rw-r--r-- | src/pager.c | 48 | ||||
-rw-r--r-- | src/sqliteInt.h | 25 | ||||
-rw-r--r-- | src/test2.c | 6 |
11 files changed, 81 insertions, 73 deletions
diff --git a/src/date.c b/src/date.c index 2fa8af762..358e7bc5a 100644 --- a/src/date.c +++ b/src/date.c @@ -16,7 +16,7 @@ ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: date.c,v 1.35 2004/09/06 17:24:12 drh Exp $ +** $Id: date.c,v 1.36 2004/10/01 02:00:31 drh Exp $ ** ** NOTES: ** @@ -47,8 +47,8 @@ ** Willmann-Bell, Inc ** Richmond, Virginia (USA) */ -#include "os.h" #include "sqliteInt.h" +#include "os.h" #include <ctype.h> #include <stdlib.h> #include <assert.h> @@ -179,10 +179,10 @@ int sqlite3OsTempFileName(char*); int sqlite3OsClose(OsFile*); int sqlite3OsRead(OsFile*, void*, int amt); int sqlite3OsWrite(OsFile*, const void*, int amt); -int sqlite3OsSeek(OsFile*, off_t offset); +int sqlite3OsSeek(OsFile*, i64 offset); int sqlite3OsSync(OsFile*); -int sqlite3OsTruncate(OsFile*, off_t size); -int sqlite3OsFileSize(OsFile*, off_t *pSize); +int sqlite3OsTruncate(OsFile*, i64 size); +int sqlite3OsFileSize(OsFile*, i64 *pSize); int sqlite3OsRandomSeed(char*); int sqlite3OsSleep(int ms); int sqlite3OsCurrentTime(double*); diff --git a/src/os_mac.c b/src/os_mac.c index cb714de73..f84c168d4 100644 --- a/src/os_mac.c +++ b/src/os_mac.c @@ -13,9 +13,9 @@ ** This file contains code that is specific classic mac. Mac OS X ** uses the os_unix.c file, not this one. */ -#include "os.h" /* Must be first to enable large file support */ -#if OS_MAC /* This file used on classic mac only */ #include "sqliteInt.h" +#include "os.h" +#if OS_MAC /* This file used on classic mac only */ #include <extras.h> #include <path2fss.h> diff --git a/src/os_mac.h b/src/os_mac.h index a5f51384d..5b60f8183 100644 --- a/src/os_mac.h +++ b/src/os_mac.h @@ -19,11 +19,6 @@ #include <unistd.h> #include <Files.h> -#ifdef _LARGE_FILE - typedef SInt64 off_t; -#else - typedef SInt32 off_t; -#endif #define SQLITE_TEMPNAME_SIZE _MAX_PATH #define SQLITE_MIN_SLEEP_MS 17 diff --git a/src/os_test.c b/src/os_test.c index 056e031ba..0e292bc42 100644 --- a/src/os_test.c +++ b/src/os_test.c @@ -13,9 +13,9 @@ ** This file contains code that is specific to Unix systems. It is used ** for testing SQLite only. */ -#include "os.h" /* Must be first to enable large file support */ #if OS_TEST /* This file is used for the test backend only */ #include "sqliteInt.h" +#include "os.h" /* Must be first to enable large file support */ #define sqlite3OsOpenReadWrite sqlite3RealOpenReadWrite #define sqlite3OsOpenExclusive sqlite3RealOpenExclusive @@ -149,7 +149,7 @@ static void closeFile(OsFile *id){ ** Return the current seek offset from the start of the file. This ** is unix-only code. */ -static off_t osTell(OsTestFile *pFile){ +static i64 osTell(OsTestFile *pFile){ return lseek(pFile->fd.h, 0, SEEK_CUR); } @@ -167,7 +167,7 @@ static int cacheBlock(OsTestFile *pFile, int blk){ } if( !pFile->apBlk[blk] ){ - off_t filesize; + i64 filesize; int rc; u8 *p = sqliteMalloc(BLOCKSIZE); @@ -201,7 +201,7 @@ static int cacheBlock(OsTestFile *pFile, int blk){ static int writeCache2(OsTestFile *pFile, int crash){ int i; int nMax = pFile->nMaxWrite; - off_t offset; + i64 offset; int rc = SQLITE_OK; offset = osTell(pFile); @@ -295,8 +295,8 @@ int sqlite3OsClose(OsFile *id){ } int sqlite3OsRead(OsFile *id, void *pBuf, int amt){ - off_t offset; /* The current offset from the start of the file */ - off_t end; /* The byte just past the last byte read */ + i64 offset; /* The current offset from the start of the file */ + i64 end; /* The byte just past the last byte read */ int blk; /* Block number the read starts on */ int i; u8 *zCsr; @@ -340,8 +340,8 @@ int sqlite3OsRead(OsFile *id, void *pBuf, int amt){ } int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){ - off_t offset; /* The current offset from the start of the file */ - off_t end; /* The byte just past the last byte written */ + i64 offset; /* The current offset from the start of the file */ + i64 end; /* The byte just past the last byte written */ int blk; /* Block number the write starts on */ int i; const u8 *zCsr; @@ -403,7 +403,7 @@ int sqlite3OsSync(OsFile *id){ ** file size to ensure that nothing in the write-cache past this point ** is written to disk. */ -int sqlite3OsTruncate(OsFile *id, off_t nByte){ +int sqlite3OsTruncate(OsFile *id, i64 nByte){ (*id)->nMaxWrite = nByte; return sqlite3RealTruncate(&(*id)->fd, nByte); } @@ -412,7 +412,7 @@ int sqlite3OsTruncate(OsFile *id, off_t nByte){ ** Return the size of the file. If the cache contains a write that extended ** the file, then return this size instead of the on-disk size. */ -int sqlite3OsFileSize(OsFile *id, off_t *pSize){ +int sqlite3OsFileSize(OsFile *id, i64 *pSize){ int rc = sqlite3RealFileSize(&(*id)->fd, pSize); if( rc==SQLITE_OK && pSize && *pSize<(*id)->nMaxWrite ){ *pSize = (*id)->nMaxWrite; @@ -442,7 +442,7 @@ int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){ ** These six function calls are passed straight through to the os_unix.c ** backend. */ -int sqlite3OsSeek(OsFile *id, off_t offset){ +int sqlite3OsSeek(OsFile *id, i64 offset){ return sqlite3RealSeek(&(*id)->fd, offset); } int sqlite3OsCheckReservedLock(OsFile *id){ diff --git a/src/os_unix.c b/src/os_unix.c index 003f039be..aab518f47 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -12,9 +12,9 @@ ** ** This file contains code that is specific to Unix systems. */ -#include "os.h" /* Must be first to enable large file support */ -#if OS_UNIX /* This file is used on unix only */ #include "sqliteInt.h" +#include "os.h" +#if OS_UNIX /* This file is used on unix only */ #include <time.h> @@ -34,6 +34,7 @@ # define O_BINARY 0 #endif + /* ** The DJGPP compiler environment looks mostly like Unix, but it ** lacks the fcntl() system call. So redefine fcntl() to be something @@ -662,7 +663,7 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){ /* ** Move the read/write pointer in a file. */ -int sqlite3OsSeek(OsFile *id, off_t offset){ +int sqlite3OsSeek(OsFile *id, i64 offset){ assert( id->isOpen ); SEEK(offset/1024 + 1); lseek(id->h, offset, SEEK_SET); @@ -733,7 +734,7 @@ int sqlite3OsSyncDirectory(const char *zDirname){ /* ** Truncate an open file to a specified size */ -int sqlite3OsTruncate(OsFile *id, off_t nByte){ +int sqlite3OsTruncate(OsFile *id, i64 nByte){ assert( id->isOpen ); SimulateIOError(SQLITE_IOERR); return ftruncate(id->h, nByte)==0 ? SQLITE_OK : SQLITE_IOERR; @@ -742,7 +743,7 @@ int sqlite3OsTruncate(OsFile *id, off_t nByte){ /* ** Determine the current size of a file in bytes */ -int sqlite3OsFileSize(OsFile *id, off_t *pSize){ +int sqlite3OsFileSize(OsFile *id, i64 *pSize){ struct stat buf; assert( id->isOpen ); SimulateIOError(SQLITE_IOERR); diff --git a/src/os_win.c b/src/os_win.c index ca062c097..9a29c2553 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -12,9 +12,9 @@ ** ** This file contains code that is specific to windows. */ -#include "os.h" /* Must be first to enable large file support */ -#if OS_WIN /* This file is used for windows only */ #include "sqliteInt.h" +#include "os.h" +#if OS_WIN /* This file is used for windows only */ #include <winbase.h> @@ -293,7 +293,7 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){ /* ** Move the read/write pointer in a file. */ -int sqlite3OsSeek(OsFile *id, off_t offset){ +int sqlite3OsSeek(OsFile *id, i64 offset){ LONG upperBits = offset>>32; LONG lowerBits = offset & 0xffffffff; DWORD rc; @@ -329,7 +329,7 @@ int sqlite3OsSyncDirectory(const char *zDirname){ /* ** Truncate an open file to a specified size */ -int sqlite3OsTruncate(OsFile *id, off_t nByte){ +int sqlite3OsTruncate(OsFile *id, i64 nByte){ LONG upperBits = nByte>>32; assert( id->isOpen ); TRACE3("TRUNCATE %d %lld\n", id->h, nByte); @@ -342,12 +342,12 @@ int sqlite3OsTruncate(OsFile *id, off_t nByte){ /* ** Determine the current size of a file in bytes */ -int sqlite3OsFileSize(OsFile *id, off_t *pSize){ +int sqlite3OsFileSize(OsFile *id, i64 *pSize){ DWORD upperBits, lowerBits; assert( id->isOpen ); SimulateIOError(SQLITE_IOERR); lowerBits = GetFileSize(id->h, &upperBits); - *pSize = (((off_t)upperBits)<<32) + lowerBits; + *pSize = (((i64)upperBits)<<32) + lowerBits; return SQLITE_OK; } diff --git a/src/os_win.h b/src/os_win.h index c85e23112..baf937b21 100644 --- a/src/os_win.h +++ b/src/os_win.h @@ -18,17 +18,6 @@ #include <windows.h> #include <winbase.h> -#if defined(_MSC_VER) || defined(__BORLANDC__) - typedef __int64 off_t; -#else -# if !defined(_CYGWIN_TYPES_H) - typedef long long off_t; -# if defined(__MINGW32__) -# define _OFF_T_ -# endif -# endif -#endif - /* ** The OsFile structure is a operating-system independing representation ** of an open file handle. It is defined differently for each architecture. diff --git a/src/pager.c b/src/pager.c index a40df566a..d62c490d9 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,10 +18,10 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.164 2004/09/24 22:32:31 drh Exp $ +** @(#) $Id: pager.c,v 1.165 2004/10/01 02:00:31 drh Exp $ */ -#include "os.h" /* Must be first to enable large file support */ #include "sqliteInt.h" +#include "os.h" #include "pager.h" #include <assert.h> #include <string.h> @@ -190,7 +190,7 @@ struct Pager { int dbSize; /* Number of pages in the file */ int origDbSize; /* dbSize before the current change */ int stmtSize; /* Size of database (in pages) at stmt_begin() */ - off_t stmtJSize; /* Size of journal at stmt_begin() */ + i64 stmtJSize; /* Size of journal at stmt_begin() */ int nRec; /* Number of pages written to the journal */ u32 cksumInit; /* Quasi-random value added to every checksum */ int stmtNRec; /* Number of records in stmt subjournal */ @@ -228,10 +228,10 @@ struct Pager { PgHdr *pFirstSynced; /* First free page with PgHdr.needSync==0 */ PgHdr *pAll; /* List of all pages */ PgHdr *pStmt; /* List of pages in the statement subjournal */ - off_t journalOff; /* Current byte offset in the journal file */ - off_t journalHdr; /* Byte offset to previous journal header */ - off_t stmtHdrOff; /* First journal header written this statement */ - off_t stmtCksum; /* cksumInit when statement was started */ + i64 journalOff; /* Current byte offset in the journal file */ + i64 journalHdr; /* Byte offset to previous journal header */ + i64 stmtHdrOff; /* First journal header written this statement */ + i64 stmtCksum; /* cksumInit when statement was started */ int sectorSize; /* Assumed sector size during rollback */ PgHdr *aHash[N_PG_HASH]; /* Hash table to map page number to PgHdr */ }; @@ -399,7 +399,7 @@ static int pager_errcode(Pager *pPager){ static int readMasterJournal(OsFile *pJrnl, char **pzMaster){ int rc; u32 len; - off_t szJ; + i64 szJ; u32 cksum; int i; unsigned char aMagic[8]; /* A buffer to hold the magic header */ @@ -469,8 +469,8 @@ static int readMasterJournal(OsFile *pJrnl, char **pzMaster){ ** */ static int seekJournalHdr(Pager *pPager){ - off_t offset = 0; - off_t c = pPager->journalOff; + i64 offset = 0; + i64 c = pPager->journalOff; if( c ){ offset = ((c-1)/JOURNAL_HDR_SZ(pPager) + 1) * JOURNAL_HDR_SZ(pPager); } @@ -562,7 +562,7 @@ static int writeJournalHdr(Pager *pPager){ */ static int readJournalHdr( Pager *pPager, - off_t journalSize, + i64 journalSize, u32 *pNRec, u32 *pDbSize ){ @@ -871,7 +871,7 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){ assert( pPager->state>=PAGER_EXCLUSIVE || pPg ); TRACE3("PLAYBACK %d page %d\n", pPager->fd.h, pgno); if( pPager->state>=PAGER_EXCLUSIVE ){ - sqlite3OsSeek(&pPager->fd, (pgno-1)*(off_t)pPager->pageSize); + sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize); rc = sqlite3OsWrite(&pPager->fd, aData, pPager->pageSize); } if( pPg ){ @@ -911,7 +911,7 @@ static int pager_delmaster(const char *zMaster){ int master_open = 0; OsFile master; char *zMasterJournal = 0; /* Contents of master journal file */ - off_t nMasterJournal; /* Size of master journal file */ + i64 nMasterJournal; /* Size of master journal file */ /* Open the master journal file exclusively in case some other process ** is running this routine also. Not that it makes too much difference. @@ -996,7 +996,7 @@ static int pager_reload_cache(Pager *pPager){ char zBuf[SQLITE_MAX_PAGE_SIZE]; if( !pPg->dirty ) continue; if( (int)pPg->pgno <= pPager->origDbSize ){ - sqlite3OsSeek(&pPager->fd, pPager->pageSize*(off_t)(pPg->pgno-1)); + sqlite3OsSeek(&pPager->fd, pPager->pageSize*(i64)(pPg->pgno-1)); rc = sqlite3OsRead(&pPager->fd, zBuf, pPager->pageSize); TRACE3("REFETCH %d page %d\n", pPager->fd.h, pPg->pgno); if( rc ) break; @@ -1023,7 +1023,7 @@ static int pager_reload_cache(Pager *pPager){ ** indicated. */ static int pager_truncate(Pager *pPager, int nPage){ - return sqlite3OsTruncate(&pPager->fd, pPager->pageSize*(off_t)nPage); + return sqlite3OsTruncate(&pPager->fd, pPager->pageSize*(i64)nPage); } /* @@ -1080,7 +1080,7 @@ static int pager_truncate(Pager *pPager, int nPage){ ** and an error code is returned. */ static int pager_playback(Pager *pPager){ - off_t szJ; /* Size of the journal file in bytes */ + i64 szJ; /* Size of the journal file in bytes */ u32 nRec; /* Number of Records in the journal */ int i; /* Loop counter */ Pgno mxPg = 0; /* Size of the original file in pages */ @@ -1215,8 +1215,8 @@ end_playback: ** at offset pPager->stmtJSize. */ static int pager_stmt_playback(Pager *pPager){ - off_t szJ; /* Size of the full journal */ - off_t hdrOff; + i64 szJ; /* Size of the full journal */ + i64 hdrOff; int nRec; /* Number of Records */ int i; /* Loop counter */ int rc; @@ -1224,7 +1224,7 @@ static int pager_stmt_playback(Pager *pPager){ szJ = pPager->journalOff; #ifndef NDEBUG { - off_t os_szJ; + i64 os_szJ; rc = sqlite3OsFileSize(&pPager->jfd, &os_szJ); if( rc!=SQLITE_OK ) return rc; assert( szJ==os_szJ ); @@ -1566,7 +1566,7 @@ void sqlite3pager_read_fileheader(Pager *pPager, int N, unsigned char *pDest){ ** pPager. */ int sqlite3pager_pagecount(Pager *pPager){ - off_t n; + i64 n; assert( pPager!=0 ); if( pPager->dbSize>=0 ){ return pPager->dbSize; @@ -1852,7 +1852,7 @@ static int syncJournal(Pager *pPager){ /* Make sure the pPager->nRec counter we are keeping agrees ** with the nRec computed from the size of the journal file. */ - off_t jSz; + i64 jSz; rc = sqlite3OsFileSize(&pPager->jfd, &jSz); if( rc!=0 ) return rc; assert( pPager->journalOff==jSz ); @@ -1949,7 +1949,7 @@ static int pager_write_pagelist(PgHdr *pList){ while( pList ){ assert( pList->dirty ); - sqlite3OsSeek(&pPager->fd, (pList->pgno-1)*(off_t)pPager->pageSize); + sqlite3OsSeek(&pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize); CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 6); TRACE3("STORE %d page %d\n", pPager->fd.h, pList->pgno); rc = sqlite3OsWrite(&pPager->fd, PGHDR_TO_DATA(pList), pPager->pageSize); @@ -2226,12 +2226,12 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){ }else{ int rc; assert( pPager->memDb==0 ); - sqlite3OsSeek(&pPager->fd, (pgno-1)*(off_t)pPager->pageSize); + sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize); rc = sqlite3OsRead(&pPager->fd, PGHDR_TO_DATA(pPg), pPager->pageSize); TRACE3("FETCH %d page %d\n", pPager->fd.h, pPg->pgno); CODEC(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3); if( rc!=SQLITE_OK ){ - off_t fileSize; + i64 fileSize; if( sqlite3OsFileSize(&pPager->fd,&fileSize)!=SQLITE_OK || fileSize>=pgno*pPager->pageSize ){ sqlite3pager_unref(PGHDR_TO_DATA(pPg)); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index ea7b1a92d..e8946f256 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,11 +11,34 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.324 2004/09/25 14:39:19 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.325 2004/10/01 02:00:31 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ +/* +** These #defines should enable >2GB file support on Posix if the +** underlying operating system supports it. If the OS lacks +** large file support, or if the OS is windows, these should be no-ops. +** +** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch +** on the compiler command line. This is necessary if you are compiling +** on a recent machine (ex: RedHat 7.2) but you want your code to work +** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2 +** without this option, LFS is enable. But LFS does not exist in the kernel +** in RedHat 6.0, so the code won't work. Hence, for maximum binary +** portability you should omit LFS. +** +** Similar is true for MacOS. LFS is only supported on MacOS 9 and later. +*/ +#ifndef SQLITE_DISABLE_LFS +# define _LARGE_FILE 1 +# ifndef _FILE_OFFSET_BITS +# define _FILE_OFFSET_BITS 64 +# endif +# define _LARGEFILE_SOURCE 1 +#endif + #include "config.h" #include "sqlite3.h" #include "hash.h" diff --git a/src/test2.c b/src/test2.c index 8c184fab3..28dc78c46 100644 --- a/src/test2.c +++ b/src/test2.c @@ -13,10 +13,10 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test2.c,v 1.25 2004/09/08 20:13:06 drh Exp $ +** $Id: test2.c,v 1.26 2004/10/01 02:00:31 drh Exp $ */ -#include "os.h" #include "sqliteInt.h" +#include "os.h" #include "pager.h" #include "tcl.h" #include <stdlib.h> @@ -497,7 +497,7 @@ static int fake_big_file( ){ int rc; int n; - off_t offset; + i64 offset; OsFile fd; int readOnly = 0; if( argc!=3 ){ |