drh | 054889e | 2005-11-30 03:20:31 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
drh | 3f45902 | 2006-01-07 16:06:07 +0000 | [diff] [blame] | 16 | #define _SQLITE_OS_C_ 1 |
drh | 054889e | 2005-11-30 03:20:31 +0000 | [diff] [blame] | 17 | #include "sqliteInt.h" |
| 18 | #include "os.h" |
drh | bd08af4 | 2007-04-05 21:58:33 +0000 | [diff] [blame^] | 19 | #undef _SQLITE_OS_C_ |
drh | 054889e | 2005-11-30 03:20:31 +0000 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | ** The following routines are convenience wrappers around methods |
| 23 | ** of the OsFile object. This is mostly just syntactic sugar. All |
| 24 | ** of this would be completely automatic if SQLite were coded using |
| 25 | ** C++ instead of plain old C. |
| 26 | */ |
| 27 | int sqlite3OsClose(OsFile **pId){ |
| 28 | OsFile *id; |
| 29 | if( pId!=0 && (id = *pId)!=0 ){ |
| 30 | return id->pMethod->xClose(pId); |
| 31 | }else{ |
| 32 | return SQLITE_OK; |
| 33 | } |
| 34 | } |
| 35 | int sqlite3OsOpenDirectory(OsFile *id, const char *zName){ |
| 36 | return id->pMethod->xOpenDirectory(id, zName); |
| 37 | } |
| 38 | int sqlite3OsRead(OsFile *id, void *pBuf, int amt){ |
| 39 | return id->pMethod->xRead(id, pBuf, amt); |
| 40 | } |
| 41 | int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){ |
| 42 | return id->pMethod->xWrite(id, pBuf, amt); |
| 43 | } |
| 44 | int sqlite3OsSeek(OsFile *id, i64 offset){ |
| 45 | return id->pMethod->xSeek(id, offset); |
| 46 | } |
| 47 | int sqlite3OsTruncate(OsFile *id, i64 size){ |
| 48 | return id->pMethod->xTruncate(id, size); |
| 49 | } |
| 50 | int sqlite3OsSync(OsFile *id, int fullsync){ |
| 51 | return id->pMethod->xSync(id, fullsync); |
| 52 | } |
| 53 | void sqlite3OsSetFullSync(OsFile *id, int value){ |
| 54 | id->pMethod->xSetFullSync(id, value); |
| 55 | } |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 56 | #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) |
| 57 | /* This method is currently only used while interactively debugging the |
| 58 | ** pager. More specificly, it can only be used when sqlite3DebugPrintf() is |
| 59 | ** included in the build. */ |
drh | 054889e | 2005-11-30 03:20:31 +0000 | [diff] [blame] | 60 | int sqlite3OsFileHandle(OsFile *id){ |
| 61 | return id->pMethod->xFileHandle(id); |
| 62 | } |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 63 | #endif |
drh | 054889e | 2005-11-30 03:20:31 +0000 | [diff] [blame] | 64 | int sqlite3OsFileSize(OsFile *id, i64 *pSize){ |
| 65 | return id->pMethod->xFileSize(id, pSize); |
| 66 | } |
| 67 | int sqlite3OsLock(OsFile *id, int lockType){ |
| 68 | return id->pMethod->xLock(id, lockType); |
| 69 | } |
| 70 | int sqlite3OsUnlock(OsFile *id, int lockType){ |
| 71 | return id->pMethod->xUnlock(id, lockType); |
| 72 | } |
| 73 | int sqlite3OsLockState(OsFile *id){ |
| 74 | return id->pMethod->xLockState(id); |
| 75 | } |
| 76 | int sqlite3OsCheckReservedLock(OsFile *id){ |
| 77 | return id->pMethod->xCheckReservedLock(id); |
| 78 | } |
danielk1977 | b472117 | 2007-03-19 05:54:48 +0000 | [diff] [blame] | 79 | int sqlite3OsSectorSize(OsFile *id){ |
drh | 3ceeb75 | 2007-03-29 18:19:52 +0000 | [diff] [blame] | 80 | int (*xSectorSize)(OsFile*) = id->pMethod->xSectorSize; |
| 81 | return xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE; |
danielk1977 | b472117 | 2007-03-19 05:54:48 +0000 | [diff] [blame] | 82 | } |
drh | 3f45902 | 2006-01-07 16:06:07 +0000 | [diff] [blame] | 83 | |
| 84 | #ifdef SQLITE_ENABLE_REDEF_IO |
| 85 | /* |
| 86 | ** A function to return a pointer to the virtual function table. |
| 87 | ** This routine really does not accomplish very much since the |
| 88 | ** virtual function table is a global variable and anybody who |
| 89 | ** can call this function can just as easily access the variable |
| 90 | ** for themselves. Nevertheless, we include this routine for |
| 91 | ** backwards compatibility with an earlier redefinable I/O |
| 92 | ** interface design. |
| 93 | */ |
| 94 | struct sqlite3OsVtbl *sqlite3_os_switch(void){ |
| 95 | return &sqlite3Os; |
| 96 | } |
| 97 | #endif |