Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: third_party/sqlite/src/src/os.c

Issue 5626002: Update sqlite to 3.7.3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/third_party/sqlite/src
Patch Set: Remove misc change. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/sqlite/src/src/os.h ('k') | third_party/sqlite/src/src/os_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ** 2005 November 29 2 ** 2005 November 29
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
11 ****************************************************************************** 11 ******************************************************************************
12 ** 12 **
13 ** This file contains OS interface code that is common to all 13 ** This file contains OS interface code that is common to all
14 ** architectures. 14 ** architectures.
15 **
16 ** $Id: os.c,v 1.127 2009/07/27 11:41:21 danielk1977 Exp $
17 */ 15 */
18 #define _SQLITE_OS_C_ 1 16 #define _SQLITE_OS_C_ 1
19 #include "sqliteInt.h" 17 #include "sqliteInt.h"
20 #undef _SQLITE_OS_C_ 18 #undef _SQLITE_OS_C_
21 19
22 /* 20 /*
23 ** The default SQLite sqlite3_vfs implementations do not allocate 21 ** The default SQLite sqlite3_vfs implementations do not allocate
24 ** memory (actually, os_unix.c allocates a small amount of memory 22 ** memory (actually, os_unix.c allocates a small amount of memory
25 ** from within OsOpen()), but some third-party implementations may. 23 ** from within OsOpen()), but some third-party implementations may.
26 ** So we test the effects of a malloc() failing and the sqlite3OsXXX() 24 ** So we test the effects of a malloc() failing and the sqlite3OsXXX()
27 ** function returning SQLITE_IOERR_NOMEM using the DO_OS_MALLOC_TEST macro. 25 ** function returning SQLITE_IOERR_NOMEM using the DO_OS_MALLOC_TEST macro.
28 ** 26 **
29 ** The following functions are instrumented for malloc() failure 27 ** The following functions are instrumented for malloc() failure
30 ** testing: 28 ** testing:
31 ** 29 **
32 ** sqlite3OsOpen() 30 ** sqlite3OsOpen()
33 ** sqlite3OsRead() 31 ** sqlite3OsRead()
34 ** sqlite3OsWrite() 32 ** sqlite3OsWrite()
35 ** sqlite3OsSync() 33 ** sqlite3OsSync()
36 ** sqlite3OsLock() 34 ** sqlite3OsLock()
37 ** 35 **
38 */ 36 */
39 #if defined(SQLITE_TEST) && (SQLITE_OS_WIN==0) 37 #if defined(SQLITE_TEST)
40 #define DO_OS_MALLOC_TEST(x) if (!x || !sqlite3IsMemJournal(x)) { \ 38 int sqlite3_memdebug_vfs_oom_test = 1;
39 #define DO_OS_MALLOC_TEST(x) \
40 if (sqlite3_memdebug_vfs_oom_test && (!x || !sqlite3IsMemJournal(x))) { \
41 void *pTstAlloc = sqlite3Malloc(10); \ 41 void *pTstAlloc = sqlite3Malloc(10); \
42 if (!pTstAlloc) return SQLITE_IOERR_NOMEM; \ 42 if (!pTstAlloc) return SQLITE_IOERR_NOMEM; \
43 sqlite3_free(pTstAlloc); \ 43 sqlite3_free(pTstAlloc); \
44 } 44 }
45 #else 45 #else
46 #define DO_OS_MALLOC_TEST(x) 46 #define DO_OS_MALLOC_TEST(x)
47 #endif 47 #endif
48 48
49 /* 49 /*
50 ** The following routines are convenience wrappers around methods 50 ** The following routines are convenience wrappers around methods
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){ 93 int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
94 return id->pMethods->xFileControl(id, op, pArg); 94 return id->pMethods->xFileControl(id, op, pArg);
95 } 95 }
96 int sqlite3OsSectorSize(sqlite3_file *id){ 96 int sqlite3OsSectorSize(sqlite3_file *id){
97 int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize; 97 int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize;
98 return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE); 98 return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE);
99 } 99 }
100 int sqlite3OsDeviceCharacteristics(sqlite3_file *id){ 100 int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
101 return id->pMethods->xDeviceCharacteristics(id); 101 return id->pMethods->xDeviceCharacteristics(id);
102 } 102 }
103 int sqlite3OsShmLock(sqlite3_file *id, int offset, int n, int flags){
104 return id->pMethods->xShmLock(id, offset, n, flags);
105 }
106 void sqlite3OsShmBarrier(sqlite3_file *id){
107 id->pMethods->xShmBarrier(id);
108 }
109 int sqlite3OsShmUnmap(sqlite3_file *id, int deleteFlag){
110 return id->pMethods->xShmUnmap(id, deleteFlag);
111 }
112 int sqlite3OsShmMap(
113 sqlite3_file *id, /* Database file handle */
114 int iPage,
115 int pgsz,
116 int bExtend, /* True to extend file if necessary */
117 void volatile **pp /* OUT: Pointer to mapping */
118 ){
119 return id->pMethods->xShmMap(id, iPage, pgsz, bExtend, pp);
120 }
103 121
104 /* 122 /*
105 ** The next group of routines are convenience wrappers around the 123 ** The next group of routines are convenience wrappers around the
106 ** VFS methods. 124 ** VFS methods.
107 */ 125 */
108 int sqlite3OsOpen( 126 int sqlite3OsOpen(
109 sqlite3_vfs *pVfs, 127 sqlite3_vfs *pVfs,
110 const char *zPath, 128 const char *zPath,
111 sqlite3_file *pFile, 129 sqlite3_file *pFile,
112 int flags, 130 int flags,
113 int *pFlagsOut 131 int *pFlagsOut
114 ){ 132 ){
115 int rc; 133 int rc;
116 DO_OS_MALLOC_TEST(0); 134 DO_OS_MALLOC_TEST(0);
117 /* 0x7f1f is a mask of SQLITE_OPEN_ flags that are valid to be passed 135 /* 0x87f3f is a mask of SQLITE_OPEN_ flags that are valid to be passed
118 ** down into the VFS layer. Some SQLITE_OPEN_ flags (for example, 136 ** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
119 ** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before 137 ** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
120 ** reaching the VFS. */ 138 ** reaching the VFS. */
121 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x7f1f, pFlagsOut); 139 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x87f3f, pFlagsOut);
122 assert( rc==SQLITE_OK || pFile->pMethods==0 ); 140 assert( rc==SQLITE_OK || pFile->pMethods==0 );
123 return rc; 141 return rc;
124 } 142 }
125 int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ 143 int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
126 return pVfs->xDelete(pVfs, zPath, dirSync); 144 return pVfs->xDelete(pVfs, zPath, dirSync);
127 } 145 }
128 int sqlite3OsAccess( 146 int sqlite3OsAccess(
129 sqlite3_vfs *pVfs, 147 sqlite3_vfs *pVfs,
130 const char *zPath, 148 const char *zPath,
131 int flags, 149 int flags,
132 int *pResOut 150 int *pResOut
133 ){ 151 ){
134 DO_OS_MALLOC_TEST(0); 152 DO_OS_MALLOC_TEST(0);
135 return pVfs->xAccess(pVfs, zPath, flags, pResOut); 153 return pVfs->xAccess(pVfs, zPath, flags, pResOut);
136 } 154 }
137 int sqlite3OsFullPathname( 155 int sqlite3OsFullPathname(
138 sqlite3_vfs *pVfs, 156 sqlite3_vfs *pVfs,
139 const char *zPath, 157 const char *zPath,
140 int nPathOut, 158 int nPathOut,
141 char *zPathOut 159 char *zPathOut
142 ){ 160 ){
161 zPathOut[0] = 0;
143 return pVfs->xFullPathname(pVfs, zPath, nPathOut, zPathOut); 162 return pVfs->xFullPathname(pVfs, zPath, nPathOut, zPathOut);
144 } 163 }
145 #ifndef SQLITE_OMIT_LOAD_EXTENSION 164 #ifndef SQLITE_OMIT_LOAD_EXTENSION
146 void *sqlite3OsDlOpen(sqlite3_vfs *pVfs, const char *zPath){ 165 void *sqlite3OsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
147 return pVfs->xDlOpen(pVfs, zPath); 166 return pVfs->xDlOpen(pVfs, zPath);
148 } 167 }
149 void sqlite3OsDlError(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ 168 void sqlite3OsDlError(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
150 pVfs->xDlError(pVfs, nByte, zBufOut); 169 pVfs->xDlError(pVfs, nByte, zBufOut);
151 } 170 }
152 void (*sqlite3OsDlSym(sqlite3_vfs *pVfs, void *pHdle, const char *zSym))(void){ 171 void (*sqlite3OsDlSym(sqlite3_vfs *pVfs, void *pHdle, const char *zSym))(void){
153 return pVfs->xDlSym(pVfs, pHdle, zSym); 172 return pVfs->xDlSym(pVfs, pHdle, zSym);
154 } 173 }
155 void sqlite3OsDlClose(sqlite3_vfs *pVfs, void *pHandle){ 174 void sqlite3OsDlClose(sqlite3_vfs *pVfs, void *pHandle){
156 pVfs->xDlClose(pVfs, pHandle); 175 pVfs->xDlClose(pVfs, pHandle);
157 } 176 }
158 #endif /* SQLITE_OMIT_LOAD_EXTENSION */ 177 #endif /* SQLITE_OMIT_LOAD_EXTENSION */
159 int sqlite3OsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ 178 int sqlite3OsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
160 return pVfs->xRandomness(pVfs, nByte, zBufOut); 179 return pVfs->xRandomness(pVfs, nByte, zBufOut);
161 } 180 }
162 int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){ 181 int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){
163 return pVfs->xSleep(pVfs, nMicro); 182 return pVfs->xSleep(pVfs, nMicro);
164 } 183 }
165 int sqlite3OsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ 184 int sqlite3OsCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *pTimeOut){
166 return pVfs->xCurrentTime(pVfs, pTimeOut); 185 int rc;
186 /* IMPLEMENTATION-OF: R-49045-42493 SQLite will use the xCurrentTimeInt64()
187 ** method to get the current date and time if that method is available
188 ** (if iVersion is 2 or greater and the function pointer is not NULL) and
189 ** will fall back to xCurrentTime() if xCurrentTimeInt64() is
190 ** unavailable.
191 */
192 if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){
193 rc = pVfs->xCurrentTimeInt64(pVfs, pTimeOut);
194 }else{
195 double r;
196 rc = pVfs->xCurrentTime(pVfs, &r);
197 *pTimeOut = (sqlite3_int64)(r*86400000.0);
198 }
199 return rc;
167 } 200 }
168 201
169 int sqlite3OsOpenMalloc( 202 int sqlite3OsOpenMalloc(
170 sqlite3_vfs *pVfs, 203 sqlite3_vfs *pVfs,
171 const char *zFile, 204 const char *zFile,
172 sqlite3_file **ppFile, 205 sqlite3_file **ppFile,
173 int flags, 206 int flags,
174 int *pOutFlags 207 int *pOutFlags
175 ){ 208 ){
176 int rc = SQLITE_NOMEM; 209 int rc = SQLITE_NOMEM;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 */ 322 */
290 int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){ 323 int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
291 #if SQLITE_THREADSAFE 324 #if SQLITE_THREADSAFE
292 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); 325 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
293 #endif 326 #endif
294 sqlite3_mutex_enter(mutex); 327 sqlite3_mutex_enter(mutex);
295 vfsUnlink(pVfs); 328 vfsUnlink(pVfs);
296 sqlite3_mutex_leave(mutex); 329 sqlite3_mutex_leave(mutex);
297 return SQLITE_OK; 330 return SQLITE_OK;
298 } 331 }
OLDNEW
« no previous file with comments | « third_party/sqlite/src/src/os.h ('k') | third_party/sqlite/src/src/os_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698