blob: 4307a57c60bc60658690a60dc71f7bb6f9bf0b70 [file] [log] [blame]
drh054889e2005-11-30 03:20:31 +00001/*
2** 2005 November 29
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11******************************************************************************
12**
13** This file contains OS interface code that is common to all
14** architectures.
15*/
drh3f459022006-01-07 16:06:07 +000016#define _SQLITE_OS_C_ 1
drh054889e2005-11-30 03:20:31 +000017#include "sqliteInt.h"
18#include "os.h"
drhbd08af42007-04-05 21:58:33 +000019#undef _SQLITE_OS_C_
drh054889e2005-11-30 03:20:31 +000020
21/*
22** The following routines are convenience wrappers around methods
danielk197762079062007-08-15 17:08:46 +000023** of the sqlite3_file object. This is mostly just syntactic sugar. All
drh054889e2005-11-30 03:20:31 +000024** of this would be completely automatic if SQLite were coded using
25** C++ instead of plain old C.
26*/
danielk1977b4b47412007-08-17 15:53:36 +000027int sqlite3OsClose(sqlite3_file *pId){
28 if( !pId->pMethods ) return SQLITE_OK;
29 return pId->pMethods->xClose(pId);
drh054889e2005-11-30 03:20:31 +000030}
danielk197762079062007-08-15 17:08:46 +000031int sqlite3OsRead(sqlite3_file *id, void *pBuf, int amt, i64 offset){
32 return id->pMethods->xRead(id, pBuf, amt, offset);
drh054889e2005-11-30 03:20:31 +000033}
danielk197762079062007-08-15 17:08:46 +000034int sqlite3OsWrite(sqlite3_file *id, const void *pBuf, int amt, i64 offset){
35 return id->pMethods->xWrite(id, pBuf, amt, offset);
drh054889e2005-11-30 03:20:31 +000036}
danielk197762079062007-08-15 17:08:46 +000037int sqlite3OsTruncate(sqlite3_file *id, i64 size){
38 return id->pMethods->xTruncate(id, size);
drh054889e2005-11-30 03:20:31 +000039}
danielk197762079062007-08-15 17:08:46 +000040int sqlite3OsSync(sqlite3_file *id, int fullsync){
41 return id->pMethods->xSync(id, fullsync);
drh054889e2005-11-30 03:20:31 +000042}
danielk197762079062007-08-15 17:08:46 +000043int sqlite3OsFileSize(sqlite3_file *id, i64 *pSize){
44 return id->pMethods->xFileSize(id, pSize);
drh054889e2005-11-30 03:20:31 +000045}
danielk197762079062007-08-15 17:08:46 +000046int sqlite3OsLock(sqlite3_file *id, int lockType){
47 return id->pMethods->xLock(id, lockType);
drh054889e2005-11-30 03:20:31 +000048}
danielk197762079062007-08-15 17:08:46 +000049int sqlite3OsUnlock(sqlite3_file *id, int lockType){
50 return id->pMethods->xUnlock(id, lockType);
drh054889e2005-11-30 03:20:31 +000051}
danielk197762079062007-08-15 17:08:46 +000052int sqlite3OsBreakLock(sqlite3_file *id){
53 return id->pMethods->xBreakLock(id);
drh054889e2005-11-30 03:20:31 +000054}
danielk197762079062007-08-15 17:08:46 +000055int sqlite3OsCheckReservedLock(sqlite3_file *id){
56 return id->pMethods->xCheckReservedLock(id);
drh054889e2005-11-30 03:20:31 +000057}
danielk197762079062007-08-15 17:08:46 +000058int sqlite3OsSectorSize(sqlite3_file *id){
59 int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize;
drh3ceeb752007-03-29 18:19:52 +000060 return xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE;
danielk1977b4721172007-03-19 05:54:48 +000061}
danielk197762079062007-08-15 17:08:46 +000062int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
63 return id->pMethods->xDeviceCharacteristics(id);
64}
drh3f459022006-01-07 16:06:07 +000065
drh87cc3b32007-05-08 21:45:27 +000066#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
67 /* These methods are currently only used for testing and debugging. */
danielk197762079062007-08-15 17:08:46 +000068 int sqlite3OsFileHandle(sqlite3_file *id){
69 /* return id->pMethods->xFileHandle(id); */
70 return 0;
drh87cc3b32007-05-08 21:45:27 +000071 }
danielk197762079062007-08-15 17:08:46 +000072 int sqlite3OsLockState(sqlite3_file *id){
73 /* return id->pMethods->xLockState(id); */
74 return 0;
drh87cc3b32007-05-08 21:45:27 +000075 }
76#endif
77
danielk1977b4b47412007-08-17 15:53:36 +000078int sqlite3OsOpen(
79 sqlite3_vfs *pVfs,
80 const char *zPath,
81 sqlite3_file *pFile,
82 int flags,
83 int *pFlagsOut
84){
85 return pVfs->xOpen(pVfs->pAppData, zPath, pFile, flags, pFlagsOut);
drh3f459022006-01-07 16:06:07 +000086}
danielk1977b4b47412007-08-17 15:53:36 +000087int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath){
88 return pVfs->xDelete(pVfs->pAppData, zPath);
89}
90int sqlite3OsAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){
91 return pVfs->xAccess(pVfs->pAppData, zPath, flags);
92}
93int sqlite3OsGetTempName(sqlite3_vfs *pVfs, char *zBufOut){
94 return pVfs->xGetTempName(pVfs->pAppData, zBufOut);
95}
96int sqlite3OsFullPathname(sqlite3_vfs *pVfs, const char *zPath, char *zPathOut){
97 return pVfs->xFullPathname(pVfs->pAppData, zPath, zPathOut);
98}
99void *sqlite3OsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
100 return pVfs->xDlOpen(pVfs->pAppData, zPath);
101}
102void sqlite3OsDlError(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
103 pVfs->xDlError(pVfs->pAppData, nByte, zBufOut);
104}
105void *sqlite3OsDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol){
106 return pVfs->xDlSym(pHandle, zSymbol);
107}
108void sqlite3OsDlClose(sqlite3_vfs *pVfs, void *pHandle){
109 pVfs->xDlClose(pHandle);
110}
111int sqlite3OsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
112 return pVfs->xRandomness(pVfs->pAppData, nByte, zBufOut);
113}
114int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){
115 return pVfs->xSleep(pVfs->pAppData, nMicro);
116}
117int sqlite3OsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
118 return pVfs->xCurrentTime(pVfs->pAppData, pTimeOut);
119}
120
121int sqlite3OsOpenMalloc(
122 sqlite3_vfs *pVfs,
123 const char *zFile,
124 sqlite3_file **ppFile,
125 int flags
126){
127 int rc = SQLITE_NOMEM;
128 sqlite3_file *pFile;
129 pFile = (sqlite3_file *)sqlite3_malloc(pVfs->szOsFile);
130 if( pFile ){
131 rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, 0);
132 if( rc!=SQLITE_OK ){
133 sqlite3_free(pFile);
134 }else{
135 *ppFile = pFile;
136 }
137 }
138 return rc;
139}
140int sqlite3OsCloseFree(sqlite3_file *pFile){
141 int rc = SQLITE_OK;
142 if( pFile ){
143 rc = sqlite3OsClose(pFile);
144 sqlite3_free(pFile);
145 }
146 return rc;
147}
148
149/*
150** Default vfs implementation. Defined by the various os_X.c implementations.
151*/
152extern sqlite3_vfs sqlite3DefaultVfs;
153
154sqlite3_vfs *sqlite3_find_vfs(const char *zVfs){
155 return &sqlite3DefaultVfs;
156}
157