blob: d6b3f5a3390890249f2b228d6e51fb1ab1613308 [file] [log] [blame]
drhe3c41372001-09-17 20:25:58 +00001/*
2** 2001 September 16
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 header file (together with is companion C source-code file
14** "os.c") attempt to abstract the underlying operating system so that
15** the SQLite library will work on both POSIX and windows systems.
16*/
17#ifndef _SQLITE_OS_H_
18#define _SQLITE_OS_H_
19
drh829e8022002-11-06 14:08:11 +000020/*
drh66560ad2006-01-06 14:32:19 +000021** Figure out if we are dealing with Unix, Windows, or some other
22** operating system.
drh829e8022002-11-06 14:08:11 +000023*/
drhee2ce182007-04-02 16:45:12 +000024#if defined(OS_OTHER)
25# if OS_OTHER==1
26# undef OS_UNIX
27# define OS_UNIX 0
28# undef OS_WIN
29# define OS_WIN 0
30# undef OS_OS2
31# define OS_OS2 0
32# else
33# undef OS_OTHER
34# endif
35#endif
drh66560ad2006-01-06 14:32:19 +000036#if !defined(OS_UNIX) && !defined(OS_OTHER)
drh0ccebe72005-06-07 22:22:50 +000037# define OS_OTHER 0
drh27a32202002-03-20 00:00:29 +000038# ifndef OS_WIN
drh0d477432005-01-16 20:47:40 +000039# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
40# define OS_WIN 1
41# define OS_UNIX 0
drh60a1e4b2006-06-03 18:02:15 +000042# define OS_OS2 0
pweilbacher3f61bc72007-06-30 15:24:37 +000043# elif defined(__EMX__) || defined(_OS2) || defined(OS2) || defined(_OS2_) || defined(__OS2__)
drh60a1e4b2006-06-03 18:02:15 +000044# define OS_WIN 0
45# define OS_UNIX 0
46# define OS_OS2 1
drh0d477432005-01-16 20:47:40 +000047# else
48# define OS_WIN 0
49# define OS_UNIX 1
drh60a1e4b2006-06-03 18:02:15 +000050# define OS_OS2 0
drh27a32202002-03-20 00:00:29 +000051# endif
52# else
53# define OS_UNIX 0
drh60a1e4b2006-06-03 18:02:15 +000054# define OS_OS2 0
drh27a32202002-03-20 00:00:29 +000055# endif
drh820f3812003-01-08 13:02:52 +000056#else
drhe5e37602003-08-16 13:10:51 +000057# ifndef OS_WIN
58# define OS_WIN 0
59# endif
drh1ab43002002-01-14 09:28:19 +000060#endif
61
drh054889e2005-11-30 03:20:31 +000062
drhe3c41372001-09-17 20:25:58 +000063/*
drh9cbe6352005-11-29 03:13:21 +000064** Define the maximum size of a temporary filename
drh0ccebe72005-06-07 22:22:50 +000065*/
drh9cbe6352005-11-29 03:13:21 +000066#if OS_WIN
drha2eebaa2005-11-29 19:50:24 +000067# include <windows.h>
drh9cbe6352005-11-29 03:13:21 +000068# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
drh60a1e4b2006-06-03 18:02:15 +000069#elif OS_OS2
pweilbacher53b4bd32007-06-22 20:17:37 +000070# if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_MEMORY)
71# include <os2safe.h> /* has to be included before os2.h for linking to work */
72# endif
drh60a1e4b2006-06-03 18:02:15 +000073# define INCL_DOSDATETIME
74# define INCL_DOSFILEMGR
75# define INCL_DOSERRORS
76# define INCL_DOSMISC
77# define INCL_DOSPROCESS
pweilbacher691902e2007-06-22 20:04:36 +000078# define INCL_DOSMODULEMGR
drh60a1e4b2006-06-03 18:02:15 +000079# include <os2.h>
80# define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP)
drh9cbe6352005-11-29 03:13:21 +000081#else
82# define SQLITE_TEMPNAME_SIZE 200
drh2e66f0b2005-04-28 17:18:48 +000083#endif
drh820f3812003-01-08 13:02:52 +000084
drhb851b2c2005-03-10 14:11:12 +000085/* If the SET_FULLSYNC macro is not defined above, then make it
86** a no-op
87*/
88#ifndef SET_FULLSYNC
89# define SET_FULLSYNC(x,y)
90#endif
91
danielk19776622cce2004-05-20 11:00:52 +000092/*
drh3ceeb752007-03-29 18:19:52 +000093** The default size of a disk sector
94*/
95#ifndef SQLITE_DEFAULT_SECTOR_SIZE
96# define SQLITE_DEFAULT_SECTOR_SIZE 512
97#endif
98
99/*
drhbbd42a62004-05-22 17:41:58 +0000100** Temporary files are named starting with this prefix followed by 16 random
101** alphanumeric characters, and no file extension. They are stored in the
102** OS's standard temporary file directory, and are deleted prior to exit.
103** If sqlite is being embedded in another program, you may wish to change the
104** prefix to reflect your program's name, so that if your program exits
105** prematurely, old temporary files can be easily identified. This can be done
106** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line.
drhfd288f32006-10-31 21:27:33 +0000107**
108** 2006-10-31: The default prefix used to be "sqlite_". But then
109** Mcafee started using SQLite in their anti-virus product and it
110** started putting files with the "sqlite" name in the c:/temp folder.
111** This annoyed many windows users. Those users would then do a
112** Google search for "sqlite", find the telephone numbers of the
113** developers and call to wake them up at night and complain.
114** For this reason, the default name prefix is changed to be "sqlite"
115** spelled backwards. So the temp files are still identified, but
116** anybody smart enough to figure out the code is also likely smart
117** enough to know that calling the developer will not help get rid
118** of the file.
danielk19776622cce2004-05-20 11:00:52 +0000119*/
drhbbd42a62004-05-22 17:41:58 +0000120#ifndef TEMP_FILE_PREFIX
drhfd288f32006-10-31 21:27:33 +0000121# define TEMP_FILE_PREFIX "etilqs_"
drhbbd42a62004-05-22 17:41:58 +0000122#endif
123
danielk1977b4b47412007-08-17 15:53:36 +0000124#if 0
125
drh824d7c12006-01-06 12:03:19 +0000126/*
drh60a1e4b2006-06-03 18:02:15 +0000127** Define the interfaces for Unix, Windows, and OS/2.
drh66560ad2006-01-06 14:32:19 +0000128*/
129#if OS_UNIX
130#define sqlite3OsOpenReadWrite sqlite3UnixOpenReadWrite
131#define sqlite3OsOpenExclusive sqlite3UnixOpenExclusive
132#define sqlite3OsOpenReadOnly sqlite3UnixOpenReadOnly
133#define sqlite3OsDelete sqlite3UnixDelete
134#define sqlite3OsFileExists sqlite3UnixFileExists
135#define sqlite3OsFullPathname sqlite3UnixFullPathname
136#define sqlite3OsIsDirWritable sqlite3UnixIsDirWritable
137#define sqlite3OsSyncDirectory sqlite3UnixSyncDirectory
138#define sqlite3OsTempFileName sqlite3UnixTempFileName
139#define sqlite3OsRandomSeed sqlite3UnixRandomSeed
140#define sqlite3OsSleep sqlite3UnixSleep
141#define sqlite3OsCurrentTime sqlite3UnixCurrentTime
142#define sqlite3OsEnterMutex sqlite3UnixEnterMutex
143#define sqlite3OsLeaveMutex sqlite3UnixLeaveMutex
144#define sqlite3OsInMutex sqlite3UnixInMutex
145#define sqlite3OsThreadSpecificData sqlite3UnixThreadSpecificData
146#define sqlite3OsMalloc sqlite3GenericMalloc
147#define sqlite3OsRealloc sqlite3GenericRealloc
148#define sqlite3OsFree sqlite3GenericFree
149#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
drh761df872006-12-21 01:29:22 +0000150#define sqlite3OsDlopen sqlite3UnixDlopen
151#define sqlite3OsDlsym sqlite3UnixDlsym
152#define sqlite3OsDlclose sqlite3UnixDlclose
drh66560ad2006-01-06 14:32:19 +0000153#endif
154#if OS_WIN
155#define sqlite3OsOpenReadWrite sqlite3WinOpenReadWrite
156#define sqlite3OsOpenExclusive sqlite3WinOpenExclusive
157#define sqlite3OsOpenReadOnly sqlite3WinOpenReadOnly
158#define sqlite3OsDelete sqlite3WinDelete
159#define sqlite3OsFileExists sqlite3WinFileExists
160#define sqlite3OsFullPathname sqlite3WinFullPathname
161#define sqlite3OsIsDirWritable sqlite3WinIsDirWritable
162#define sqlite3OsSyncDirectory sqlite3WinSyncDirectory
163#define sqlite3OsTempFileName sqlite3WinTempFileName
164#define sqlite3OsRandomSeed sqlite3WinRandomSeed
165#define sqlite3OsSleep sqlite3WinSleep
166#define sqlite3OsCurrentTime sqlite3WinCurrentTime
167#define sqlite3OsEnterMutex sqlite3WinEnterMutex
168#define sqlite3OsLeaveMutex sqlite3WinLeaveMutex
169#define sqlite3OsInMutex sqlite3WinInMutex
170#define sqlite3OsThreadSpecificData sqlite3WinThreadSpecificData
171#define sqlite3OsMalloc sqlite3GenericMalloc
172#define sqlite3OsRealloc sqlite3GenericRealloc
173#define sqlite3OsFree sqlite3GenericFree
174#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
drh761df872006-12-21 01:29:22 +0000175#define sqlite3OsDlopen sqlite3WinDlopen
176#define sqlite3OsDlsym sqlite3WinDlsym
177#define sqlite3OsDlclose sqlite3WinDlclose
drh66560ad2006-01-06 14:32:19 +0000178#endif
drh60a1e4b2006-06-03 18:02:15 +0000179#if OS_OS2
180#define sqlite3OsOpenReadWrite sqlite3Os2OpenReadWrite
181#define sqlite3OsOpenExclusive sqlite3Os2OpenExclusive
182#define sqlite3OsOpenReadOnly sqlite3Os2OpenReadOnly
183#define sqlite3OsDelete sqlite3Os2Delete
184#define sqlite3OsFileExists sqlite3Os2FileExists
185#define sqlite3OsFullPathname sqlite3Os2FullPathname
186#define sqlite3OsIsDirWritable sqlite3Os2IsDirWritable
187#define sqlite3OsSyncDirectory sqlite3Os2SyncDirectory
188#define sqlite3OsTempFileName sqlite3Os2TempFileName
189#define sqlite3OsRandomSeed sqlite3Os2RandomSeed
190#define sqlite3OsSleep sqlite3Os2Sleep
191#define sqlite3OsCurrentTime sqlite3Os2CurrentTime
192#define sqlite3OsEnterMutex sqlite3Os2EnterMutex
193#define sqlite3OsLeaveMutex sqlite3Os2LeaveMutex
194#define sqlite3OsInMutex sqlite3Os2InMutex
195#define sqlite3OsThreadSpecificData sqlite3Os2ThreadSpecificData
196#define sqlite3OsMalloc sqlite3GenericMalloc
197#define sqlite3OsRealloc sqlite3GenericRealloc
198#define sqlite3OsFree sqlite3GenericFree
199#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
drh761df872006-12-21 01:29:22 +0000200#define sqlite3OsDlopen sqlite3Os2Dlopen
201#define sqlite3OsDlsym sqlite3Os2Dlsym
202#define sqlite3OsDlclose sqlite3Os2Dlclose
drh60a1e4b2006-06-03 18:02:15 +0000203#endif
204
danielk1977b4b47412007-08-17 15:53:36 +0000205#endif
drh66560ad2006-01-06 14:32:19 +0000206
pweilbacher04bd0c12006-06-24 12:38:59 +0000207
208
drh66560ad2006-01-06 14:32:19 +0000209/*
210** If using an alternative OS interface, then we must have an "os_other.h"
211** header file available for that interface. Presumably the "os_other.h"
212** header file contains #defines similar to those above.
213*/
214#if OS_OTHER
215# include "os_other.h"
216#endif
217
218
219
220/*
drh824d7c12006-01-06 12:03:19 +0000221** Forward declarations
222*/
223typedef struct OsFile OsFile;
224typedef struct IoMethod IoMethod;
drh0ccebe72005-06-07 22:22:50 +0000225
drh824d7c12006-01-06 12:03:19 +0000226/*
227** An instance of the following structure contains pointers to all
228** methods on an OsFile object.
229*/
230struct IoMethod {
231 int (*xClose)(OsFile**);
232 int (*xOpenDirectory)(OsFile*, const char*);
233 int (*xRead)(OsFile*, void*, int amt);
234 int (*xWrite)(OsFile*, const void*, int amt);
235 int (*xSeek)(OsFile*, i64 offset);
236 int (*xTruncate)(OsFile*, i64 size);
237 int (*xSync)(OsFile*, int);
238 void (*xSetFullSync)(OsFile *id, int setting);
239 int (*xFileHandle)(OsFile *id);
240 int (*xFileSize)(OsFile*, i64 *pSize);
241 int (*xLock)(OsFile*, int);
242 int (*xUnlock)(OsFile*, int);
243 int (*xLockState)(OsFile *id);
244 int (*xCheckReservedLock)(OsFile *id);
danielk1977b4721172007-03-19 05:54:48 +0000245 int (*xSectorSize)(OsFile *id);
drh824d7c12006-01-06 12:03:19 +0000246};
247
248/*
249** The OsFile object describes an open disk file in an OS-dependent way.
250** The version of OsFile defined here is a generic version. Each OS
251** implementation defines its own subclass of this structure that contains
252** additional information needed to handle file I/O. But the pMethod
253** entry (pointing to the virtual function table) always occurs first
254** so that we can always find the appropriate methods.
255*/
256struct OsFile {
257 IoMethod const *pMethod;
258};
259
260/*
261** The following values may be passed as the second argument to
262** sqlite3OsLock(). The various locks exhibit the following semantics:
263**
264** SHARED: Any number of processes may hold a SHARED lock simultaneously.
265** RESERVED: A single process may hold a RESERVED lock on a file at
266** any time. Other processes may hold and obtain new SHARED locks.
267** PENDING: A single process may hold a PENDING lock on a file at
268** any one time. Existing SHARED locks may persist, but no new
269** SHARED locks may be obtained by other processes.
270** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
271**
272** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
273** process that requests an EXCLUSIVE lock may actually obtain a PENDING
274** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
275** sqlite3OsLock().
276*/
277#define NO_LOCK 0
278#define SHARED_LOCK 1
279#define RESERVED_LOCK 2
280#define PENDING_LOCK 3
281#define EXCLUSIVE_LOCK 4
282
283/*
284** File Locking Notes: (Mostly about windows but also some info for Unix)
285**
286** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
287** those functions are not available. So we use only LockFile() and
288** UnlockFile().
289**
290** LockFile() prevents not just writing but also reading by other processes.
291** A SHARED_LOCK is obtained by locking a single randomly-chosen
292** byte out of a specific range of bytes. The lock byte is obtained at
293** random so two separate readers can probably access the file at the
294** same time, unless they are unlucky and choose the same lock byte.
295** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
296** There can only be one writer. A RESERVED_LOCK is obtained by locking
297** a single byte of the file that is designated as the reserved lock byte.
298** A PENDING_LOCK is obtained by locking a designated byte different from
299** the RESERVED_LOCK byte.
300**
301** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
302** which means we can use reader/writer locks. When reader/writer locks
303** are used, the lock is placed on the same range of bytes that is used
304** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
305** will support two or more Win95 readers or two or more WinNT readers.
306** But a single Win95 reader will lock out all WinNT readers and a single
307** WinNT reader will lock out all other Win95 readers.
308**
309** The following #defines specify the range of bytes used for locking.
310** SHARED_SIZE is the number of bytes available in the pool from which
311** a random byte is selected for a shared lock. The pool of bytes for
312** shared locks begins at SHARED_FIRST.
313**
314** These #defines are available in sqlite_aux.h so that adaptors for
315** connecting SQLite to other operating systems can use the same byte
316** ranges for locking. In particular, the same locking strategy and
317** byte ranges are used for Unix. This leaves open the possiblity of having
318** clients on win95, winNT, and unix all talking to the same shared file
319** and all locking correctly. To do so would require that samba (or whatever
320** tool is being used for file sharing) implements locks correctly between
321** windows and unix. I'm guessing that isn't likely to happen, but by
322** using the same locking range we are at least open to the possibility.
323**
324** Locking in windows is manditory. For this reason, we cannot store
325** actual data in the bytes used for locking. The pager never allocates
326** the pages involved in locking therefore. SHARED_SIZE is selected so
327** that all locks will fit on a single page even at the minimum page size.
328** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
329** is set high so that we don't have to allocate an unused page except
330** for very large databases. But one should test the page skipping logic
331** by setting PENDING_BYTE low and running the entire regression suite.
332**
333** Changing the value of PENDING_BYTE results in a subtly incompatible
334** file format. Depending on how it is changed, you might not notice
335** the incompatibility right away, even running a full regression test.
336** The default location of PENDING_BYTE is the first byte past the
337** 1GB boundary.
338**
339*/
340#ifndef SQLITE_TEST
341#define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */
342#else
343extern unsigned int sqlite3_pending_byte;
344#define PENDING_BYTE sqlite3_pending_byte
345#endif
346
347#define RESERVED_BYTE (PENDING_BYTE+1)
348#define SHARED_FIRST (PENDING_BYTE+2)
349#define SHARED_SIZE 510
350
danielk1977b4b47412007-08-17 15:53:36 +0000351/*
352** Functions for accessing sqlite3_file methods
drh824d7c12006-01-06 12:03:19 +0000353*/
danielk1977b4b47412007-08-17 15:53:36 +0000354int sqlite3OsClose(sqlite3_file*);
danielk197762079062007-08-15 17:08:46 +0000355int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
356int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
357int sqlite3OsTruncate(sqlite3_file*, i64 size);
358int sqlite3OsSync(sqlite3_file*, int);
359int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
360int sqlite3OsLock(sqlite3_file*, int);
361int sqlite3OsUnlock(sqlite3_file*, int);
362int sqlite3OsBreakLock(sqlite3_file*);
363int sqlite3OsCheckReservedLock(sqlite3_file *id);
364int sqlite3OsSectorSize(sqlite3_file *id);
365int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
366
danielk1977b4b47412007-08-17 15:53:36 +0000367/*
368** Functions for accessing sqlite3_vfs methods
369*/
370int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *);
371int sqlite3OsDelete(sqlite3_vfs *, const char *);
372int sqlite3OsAccess(sqlite3_vfs *, const char *, int);
373int sqlite3OsGetTempName(sqlite3_vfs *, char *);
374int sqlite3OsFullPathname(sqlite3_vfs *, const char *, char *);
375void *sqlite3OsDlOpen(sqlite3_vfs *, const char *);
376void sqlite3OsDlError(sqlite3_vfs *, int, char *);
377void *sqlite3OsDlSym(sqlite3_vfs *, void *, const char *);
378void sqlite3OsDlClose(sqlite3_vfs *, void *);
379int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
380int sqlite3OsSleep(sqlite3_vfs *, int);
381int sqlite3OsCurrentTime(sqlite3_vfs *, double*);
382
383/*
384** Convenience functions for opening and closing files using
385** sqlite3_malloc() to obtain space for the file-handle structure.
386*/
387int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int);
388int sqlite3OsCloseFree(sqlite3_file *);
389
390#if 0
danielk197762079062007-08-15 17:08:46 +0000391int sqlite3OsOpenReadWrite(const char*, sqlite3_file**, int*);
392int sqlite3OsOpenExclusive(const char*, sqlite3_file**, int);
393int sqlite3OsOpenReadOnly(const char*, sqlite3_file**);
drh66560ad2006-01-06 14:32:19 +0000394int sqlite3OsDelete(const char*);
395int sqlite3OsFileExists(const char*);
396char *sqlite3OsFullPathname(const char*);
397int sqlite3OsIsDirWritable(char*);
398int sqlite3OsSyncDirectory(const char*);
399int sqlite3OsTempFileName(char*);
400int sqlite3OsRandomSeed(char*);
401int sqlite3OsSleep(int ms);
402int sqlite3OsCurrentTime(double*);
403void sqlite3OsEnterMutex(void);
404void sqlite3OsLeaveMutex(void);
drh757b04e2006-01-18 17:25:45 +0000405int sqlite3OsInMutex(int);
drh6f7adc82006-01-11 21:41:20 +0000406ThreadData *sqlite3OsThreadSpecificData(int);
drh66560ad2006-01-06 14:32:19 +0000407void *sqlite3OsMalloc(int);
408void *sqlite3OsRealloc(void *, int);
409void sqlite3OsFree(void *);
410int sqlite3OsAllocationSize(void *);
drh761df872006-12-21 01:29:22 +0000411void *sqlite3OsDlopen(const char*);
412void *sqlite3OsDlsym(void*, const char*);
413int sqlite3OsDlclose(void*);
danielk1977b4b47412007-08-17 15:53:36 +0000414#endif
drh9c06c952005-11-26 00:25:00 +0000415
drh87cc3b32007-05-08 21:45:27 +0000416#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
danielk197762079062007-08-15 17:08:46 +0000417 int sqlite3OsFileHandle(sqlite3_file *id);
418 int sqlite3OsLockState(sqlite3_file *id);
drh87cc3b32007-05-08 21:45:27 +0000419#endif
420
drh3f459022006-01-07 16:06:07 +0000421/*
422** If the SQLITE_ENABLE_REDEF_IO macro is defined, then the OS-layer
423** interface routines are not called directly but are invoked using
424** pointers to functions. This allows the implementation of various
425** OS-layer interface routines to be modified at run-time. There are
426** obscure but legitimate reasons for wanting to do this. But for
427** most users, a direct call to the underlying interface is preferable
428** so the the redefinable I/O interface is turned off by default.
429*/
430#ifdef SQLITE_ENABLE_REDEF_IO
431
432/*
433** When redefinable I/O is enabled, a single global instance of the
434** following structure holds pointers to the routines that SQLite
435** uses to talk with the underlying operating system. Modify this
436** structure (before using any SQLite API!) to accomodate perculiar
437** operating system interfaces or behaviors.
438*/
439struct sqlite3OsVtbl {
danielk197762079062007-08-15 17:08:46 +0000440 int (*xOpenReadWrite)(const char*, sqlite3_file**, int*);
441 int (*xOpenExclusive)(const char*, sqlite3_file**, int);
442 int (*xOpenReadOnly)(const char*, sqlite3_file**);
drh3f459022006-01-07 16:06:07 +0000443
444 int (*xDelete)(const char*);
445 int (*xFileExists)(const char*);
446 char *(*xFullPathname)(const char*);
447 int (*xIsDirWritable)(char*);
448 int (*xSyncDirectory)(const char*);
449 int (*xTempFileName)(char*);
450
451 int (*xRandomSeed)(char*);
452 int (*xSleep)(int ms);
453 int (*xCurrentTime)(double*);
454
455 void (*xEnterMutex)(void);
456 void (*xLeaveMutex)(void);
drhbcdb6612006-01-21 19:57:50 +0000457 int (*xInMutex)(int);
drh6f7adc82006-01-11 21:41:20 +0000458 ThreadData *(*xThreadSpecificData)(int);
drh3f459022006-01-07 16:06:07 +0000459
460 void *(*xMalloc)(int);
461 void *(*xRealloc)(void *, int);
462 void (*xFree)(void *);
463 int (*xAllocationSize)(void *);
drh761df872006-12-21 01:29:22 +0000464
465 void *(*xDlopen)(const char*);
466 void *(*xDlsym)(void*, const char*);
467 int (*xDlclose)(void*);
drh3f459022006-01-07 16:06:07 +0000468};
469
470/* Macro used to comment out routines that do not exists when there is
drh761df872006-12-21 01:29:22 +0000471** no disk I/O or extension loading
drh3f459022006-01-07 16:06:07 +0000472*/
473#ifdef SQLITE_OMIT_DISKIO
474# define IF_DISKIO(X) 0
475#else
476# define IF_DISKIO(X) X
477#endif
drh761df872006-12-21 01:29:22 +0000478#ifdef SQLITE_OMIT_LOAD_EXTENSION
479# define IF_DLOPEN(X) 0
480#else
481# define IF_DLOPEN(X) X
482#endif
483
drh3f459022006-01-07 16:06:07 +0000484
drhbd08af42007-04-05 21:58:33 +0000485#if defined(_SQLITE_OS_C_) || defined(SQLITE_AMALGAMATION)
drh3f459022006-01-07 16:06:07 +0000486 /*
487 ** The os.c file implements the global virtual function table.
drhbd08af42007-04-05 21:58:33 +0000488 ** We have to put this file here because the initializers
489 ** (ex: sqlite3OsRandomSeed) are macros that are about to be
490 ** redefined.
drh3f459022006-01-07 16:06:07 +0000491 */
492 struct sqlite3OsVtbl sqlite3Os = {
493 IF_DISKIO( sqlite3OsOpenReadWrite ),
494 IF_DISKIO( sqlite3OsOpenExclusive ),
495 IF_DISKIO( sqlite3OsOpenReadOnly ),
496 IF_DISKIO( sqlite3OsDelete ),
497 IF_DISKIO( sqlite3OsFileExists ),
498 IF_DISKIO( sqlite3OsFullPathname ),
499 IF_DISKIO( sqlite3OsIsDirWritable ),
500 IF_DISKIO( sqlite3OsSyncDirectory ),
501 IF_DISKIO( sqlite3OsTempFileName ),
502 sqlite3OsRandomSeed,
503 sqlite3OsSleep,
504 sqlite3OsCurrentTime,
505 sqlite3OsEnterMutex,
506 sqlite3OsLeaveMutex,
507 sqlite3OsInMutex,
danielk1977b4b47412007-08-17 15:53:36 +0000508 0,
drh3f459022006-01-07 16:06:07 +0000509 sqlite3OsMalloc,
510 sqlite3OsRealloc,
511 sqlite3OsFree,
drh761df872006-12-21 01:29:22 +0000512 sqlite3OsAllocationSize,
513 IF_DLOPEN( sqlite3OsDlopen ),
514 IF_DLOPEN( sqlite3OsDlsym ),
515 IF_DLOPEN( sqlite3OsDlclose ),
drh3f459022006-01-07 16:06:07 +0000516 };
517#else
518 /*
519 ** Files other than os.c just reference the global virtual function table.
520 */
521 extern struct sqlite3OsVtbl sqlite3Os;
522#endif /* _SQLITE_OS_C_ */
523
524
525/* This additional API routine is available with redefinable I/O */
526struct sqlite3OsVtbl *sqlite3_os_switch(void);
527
528
529/*
530** Redefine the OS interface to go through the virtual function table
531** rather than calling routines directly.
532*/
533#undef sqlite3OsOpenReadWrite
534#undef sqlite3OsOpenExclusive
535#undef sqlite3OsOpenReadOnly
536#undef sqlite3OsDelete
537#undef sqlite3OsFileExists
538#undef sqlite3OsFullPathname
539#undef sqlite3OsIsDirWritable
540#undef sqlite3OsSyncDirectory
541#undef sqlite3OsTempFileName
542#undef sqlite3OsRandomSeed
543#undef sqlite3OsSleep
544#undef sqlite3OsCurrentTime
545#undef sqlite3OsEnterMutex
546#undef sqlite3OsLeaveMutex
547#undef sqlite3OsInMutex
548#undef sqlite3OsThreadSpecificData
549#undef sqlite3OsMalloc
550#undef sqlite3OsRealloc
551#undef sqlite3OsFree
552#undef sqlite3OsAllocationSize
553#define sqlite3OsOpenReadWrite sqlite3Os.xOpenReadWrite
554#define sqlite3OsOpenExclusive sqlite3Os.xOpenExclusive
555#define sqlite3OsOpenReadOnly sqlite3Os.xOpenReadOnly
556#define sqlite3OsDelete sqlite3Os.xDelete
557#define sqlite3OsFileExists sqlite3Os.xFileExists
558#define sqlite3OsFullPathname sqlite3Os.xFullPathname
559#define sqlite3OsIsDirWritable sqlite3Os.xIsDirWritable
560#define sqlite3OsSyncDirectory sqlite3Os.xSyncDirectory
561#define sqlite3OsTempFileName sqlite3Os.xTempFileName
562#define sqlite3OsRandomSeed sqlite3Os.xRandomSeed
563#define sqlite3OsSleep sqlite3Os.xSleep
564#define sqlite3OsCurrentTime sqlite3Os.xCurrentTime
565#define sqlite3OsEnterMutex sqlite3Os.xEnterMutex
566#define sqlite3OsLeaveMutex sqlite3Os.xLeaveMutex
567#define sqlite3OsInMutex sqlite3Os.xInMutex
568#define sqlite3OsThreadSpecificData sqlite3Os.xThreadSpecificData
569#define sqlite3OsMalloc sqlite3Os.xMalloc
570#define sqlite3OsRealloc sqlite3Os.xRealloc
571#define sqlite3OsFree sqlite3Os.xFree
572#define sqlite3OsAllocationSize sqlite3Os.xAllocationSize
573
574#endif /* SQLITE_ENABLE_REDEF_IO */
575
drhe3c41372001-09-17 20:25:58 +0000576#endif /* _SQLITE_OS_H_ */