Back to index

lightning-sunbird  0.9+nobinonly
sqlite3file.h
Go to the documentation of this file.
00001 //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla History System
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Google Inc.
00019  * Portions created by the Initial Developer are Copyright (C) 2006
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Brett Wilson <brettw@gmail.com> (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 
00050 extern "C" {
00051 
00052 struct ThreadData;
00053 
00054 /* FROM sqliteInt.h
00055 ** ----------------
00056 ** Some compilers do not support the "long long" datatype.  So we have
00057 ** to do a typedef that for 64-bit integers that depends on what compiler
00058 ** is being used.
00059 */
00060 #if defined(_MSC_VER) || defined(__BORLANDC__)
00061   typedef __int64 sqlite_int64;
00062   typedef unsigned __int64 sqlite_uint64;
00063 #else
00064   typedef long long int sqlite_int64;
00065   typedef unsigned long long int sqlite_uint64;
00066 #endif
00067 
00068 /* FROM sqliteInt.h
00069 ** ----------------
00070 ** Call this to check for out of memory errors when returning.
00071 ** See definition in util.c
00072 */
00073 struct sqlite3;
00074 int sqlite3ApiExit(sqlite3 *db, int);
00075 
00076 
00077 /*
00078 ** Forward declarations
00079 */
00080 typedef struct OsFile OsFile;
00081 typedef struct IoMethod IoMethod;
00082 
00083 /* FROM os.h
00084 ** ---------
00085 ** An instance of the following structure contains pointers to all
00086 ** methods on an OsFile object.
00087 */
00088 struct IoMethod {
00089   int (*xClose)(OsFile**);
00090   int (*xOpenDirectory)(OsFile*, const char*);
00091   int (*xRead)(OsFile*, void*, int amt);
00092   int (*xWrite)(OsFile*, const void*, int amt);
00093   int (*xSeek)(OsFile*, sqlite_int64 offset);
00094   int (*xTruncate)(OsFile*, sqlite_int64 size);
00095   int (*xSync)(OsFile*, int);
00096   void (*xSetFullSync)(OsFile *id, int setting);
00097   int (*xFileHandle)(OsFile *id);
00098   int (*xFileSize)(OsFile*, sqlite_int64 *pSize);
00099   int (*xLock)(OsFile*, int);
00100   int (*xUnlock)(OsFile*, int);
00101   int (*xLockState)(OsFile *id);
00102   int (*xCheckReservedLock)(OsFile *id);
00103 };
00104 
00105 /* FROM os.h
00106 ** ---------
00107 ** The OsFile object describes an open disk file in an OS-dependent way.
00108 ** The version of OsFile defined here is a generic version.  Each OS
00109 ** implementation defines its own subclass of this structure that contains
00110 ** additional information needed to handle file I/O.  But the pMethod
00111 ** entry (pointing to the virtual function table) always occurs first
00112 ** so that we can always find the appropriate methods.
00113 */
00114 struct OsFile {
00115   IoMethod const *pMethod;
00116 };
00117 
00118 /* FROM os.h
00119 ** ---------
00120 ** When redefinable I/O is enabled, a single global instance of the
00121 ** following structure holds pointers to the routines that SQLite 
00122 ** uses to talk with the underlying operating system.  Modify this
00123 ** structure (before using any SQLite API!) to accomodate perculiar
00124 ** operating system interfaces or behaviors.
00125 */
00126 struct sqlite3OsVtbl {
00127   int (*xOpenReadWrite)(const char*, OsFile**, int*);
00128   int (*xOpenExclusive)(const char*, OsFile**, int);
00129   int (*xOpenReadOnly)(const char*, OsFile**);
00130 
00131   int (*xDelete)(const char*);
00132   int (*xFileExists)(const char*);
00133   char *(*xFullPathname)(const char*);
00134   int (*xIsDirWritable)(char*);
00135   int (*xSyncDirectory)(const char*);
00136   int (*xTempFileName)(char*);
00137 
00138   int (*xRandomSeed)(char*);
00139   int (*xSleep)(int ms);
00140   int (*xCurrentTime)(double*);
00141 
00142   void (*xEnterMutex)(void);
00143   void (*xLeaveMutex)(void);
00144   int (*xInMutex)(int);
00145   ThreadData *(*xThreadSpecificData)(int);
00146 
00147   void *(*xMalloc)(int);
00148   void *(*xRealloc)(void *, int);
00149   void (*xFree)(void *);
00150   int (*xAllocationSize)(void *);
00151 };
00152 
00153 /* FROM os.h
00154 ** ---------
00155 ** Macro used to comment out routines that do not exists when there is
00156 ** no disk I/O 
00157 */
00158 #ifdef SQLITE_OMIT_DISKIO
00159 # define IF_DISKIO(X)  0
00160 #else
00161 # define IF_DISKIO(X)  X
00162 #endif
00163 
00164 #ifdef _SQLITE_OS_C_
00165   /*
00166   ** The os.c file implements the global virtual function table.
00167   */
00168   struct sqlite3OsVtbl sqlite3Os = {
00169     IF_DISKIO( sqlite3OsOpenReadWrite ),
00170     IF_DISKIO( sqlite3OsOpenExclusive ),
00171     IF_DISKIO( sqlite3OsOpenReadOnly ),
00172     IF_DISKIO( sqlite3OsDelete ),
00173     IF_DISKIO( sqlite3OsFileExists ),
00174     IF_DISKIO( sqlite3OsFullPathname ),
00175     IF_DISKIO( sqlite3OsIsDirWritable ),
00176     IF_DISKIO( sqlite3OsSyncDirectory ),
00177     IF_DISKIO( sqlite3OsTempFileName ),
00178     sqlite3OsRandomSeed,
00179     sqlite3OsSleep,
00180     sqlite3OsCurrentTime,
00181     sqlite3OsEnterMutex,
00182     sqlite3OsLeaveMutex,
00183     sqlite3OsInMutex,
00184     sqlite3OsThreadSpecificData,
00185     sqlite3OsMalloc,
00186     sqlite3OsRealloc,
00187     sqlite3OsFree,
00188     sqlite3OsAllocationSize
00189   };
00190 #else
00191   /*
00192   ** Files other than os.c just reference the global virtual function table. 
00193   */
00194   extern struct sqlite3OsVtbl sqlite3Os;
00195 #endif /* _SQLITE_OS_C_ */
00196 
00197 
00198 /* FROM os.h
00199 ** ---------
00200 ** This additional API routine is available with redefinable I/O
00201 */
00202 struct sqlite3OsVtbl *sqlite3_os_switch(void);
00203 
00204 } // extern "C"