disable the egl demos.
[AROS-Contrib.git] / sqlite3 / os.h
blobae9f4fbf2e7ef35b9675ccc419eb90f8f80ce935
1 /*
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.
11 ******************************************************************************
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.
17 #ifndef _SQLITE_OS_H_
18 #define _SQLITE_OS_H_
21 ** Figure out if we are dealing with Unix, Windows or MacOS.
23 ** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
24 ** The MacOS build is designed to use CodeWarrior (tested with v8)
26 #if !defined(OS_UNIX) && !defined(OS_TEST) && !defined(OS_OTHER)
27 # define OS_OTHER 0
28 # ifndef OS_WIN
29 # if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
30 # define OS_WIN 1
31 # define OS_UNIX 0
32 # elif OS_AROS
33 # define OS_WIN 0
34 # define OS_UNIX 0
35 # else
36 # define OS_WIN 0
37 # define OS_UNIX 1
38 # endif
39 # else
40 # define OS_UNIX 0
41 # endif
42 #else
43 # ifndef OS_WIN
44 # define OS_WIN 0
45 # endif
46 #endif
49 ** Invoke the appropriate operating-system specific header file.
51 #if OS_TEST
52 # include "os_test.h"
53 #endif
54 #if OS_UNIX
55 # include "os_unix.h"
56 #endif
57 #if OS_WIN
58 # include "os_win.h"
59 #endif
60 #if OS_AROS
61 # include "os_aros.h"
62 #endif
64 /* os_other.c and os_other.h are not delivered with SQLite. These files
65 ** are place-holders that can be filled in by third-party developers to
66 ** implement backends to their on proprietary operating systems.
68 #if OS_OTHER
69 # include "os_other.h"
70 #endif
72 /* If the SET_FULLSYNC macro is not defined above, then make it
73 ** a no-op
75 #ifndef SET_FULLSYNC
76 # define SET_FULLSYNC(x,y)
77 #endif
80 ** Temporary files are named starting with this prefix followed by 16 random
81 ** alphanumeric characters, and no file extension. They are stored in the
82 ** OS's standard temporary file directory, and are deleted prior to exit.
83 ** If sqlite is being embedded in another program, you may wish to change the
84 ** prefix to reflect your program's name, so that if your program exits
85 ** prematurely, old temporary files can be easily identified. This can be done
86 ** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line.
88 #ifndef TEMP_FILE_PREFIX
89 # define TEMP_FILE_PREFIX "sqlite_"
90 #endif
93 ** The following values may be passed as the second argument to
94 ** sqlite3OsLock(). The various locks exhibit the following semantics:
96 ** SHARED: Any number of processes may hold a SHARED lock simultaneously.
97 ** RESERVED: A single process may hold a RESERVED lock on a file at
98 ** any time. Other processes may hold and obtain new SHARED locks.
99 ** PENDING: A single process may hold a PENDING lock on a file at
100 ** any one time. Existing SHARED locks may persist, but no new
101 ** SHARED locks may be obtained by other processes.
102 ** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
104 ** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
105 ** process that requests an EXCLUSIVE lock may actually obtain a PENDING
106 ** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
107 ** sqlite3OsLock().
109 #define NO_LOCK 0
110 #define SHARED_LOCK 1
111 #define RESERVED_LOCK 2
112 #define PENDING_LOCK 3
113 #define EXCLUSIVE_LOCK 4
116 ** File Locking Notes: (Mostly about windows but also some info for Unix)
118 ** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
119 ** those functions are not available. So we use only LockFile() and
120 ** UnlockFile().
122 ** LockFile() prevents not just writing but also reading by other processes.
123 ** A SHARED_LOCK is obtained by locking a single randomly-chosen
124 ** byte out of a specific range of bytes. The lock byte is obtained at
125 ** random so two separate readers can probably access the file at the
126 ** same time, unless they are unlucky and choose the same lock byte.
127 ** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
128 ** There can only be one writer. A RESERVED_LOCK is obtained by locking
129 ** a single byte of the file that is designated as the reserved lock byte.
130 ** A PENDING_LOCK is obtained by locking a designated byte different from
131 ** the RESERVED_LOCK byte.
133 ** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
134 ** which means we can use reader/writer locks. When reader/writer locks
135 ** are used, the lock is placed on the same range of bytes that is used
136 ** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
137 ** will support two or more Win95 readers or two or more WinNT readers.
138 ** But a single Win95 reader will lock out all WinNT readers and a single
139 ** WinNT reader will lock out all other Win95 readers.
141 ** The following #defines specify the range of bytes used for locking.
142 ** SHARED_SIZE is the number of bytes available in the pool from which
143 ** a random byte is selected for a shared lock. The pool of bytes for
144 ** shared locks begins at SHARED_FIRST.
146 ** These #defines are available in os.h so that Unix can use the same
147 ** byte ranges for locking. This leaves open the possiblity of having
148 ** clients on win95, winNT, and unix all talking to the same shared file
149 ** and all locking correctly. To do so would require that samba (or whatever
150 ** tool is being used for file sharing) implements locks correctly between
151 ** windows and unix. I'm guessing that isn't likely to happen, but by
152 ** using the same locking range we are at least open to the possibility.
154 ** Locking in windows is manditory. For this reason, we cannot store
155 ** actual data in the bytes used for locking. The pager never allocates
156 ** the pages involved in locking therefore. SHARED_SIZE is selected so
157 ** that all locks will fit on a single page even at the minimum page size.
158 ** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
159 ** is set high so that we don't have to allocate an unused page except
160 ** for very large databases. But one should test the page skipping logic
161 ** by setting PENDING_BYTE low and running the entire regression suite.
163 ** Changing the value of PENDING_BYTE results in a subtly incompatible
164 ** file format. Depending on how it is changed, you might not notice
165 ** the incompatibility right away, even running a full regression test.
166 ** The default location of PENDING_BYTE is the first byte past the
167 ** 1GB boundary.
170 #define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */
171 /* #define PENDING_BYTE 0x5400 // Page 22 - for testing */
172 #define RESERVED_BYTE (PENDING_BYTE+1)
173 #define SHARED_FIRST (PENDING_BYTE+2)
174 #define SHARED_SIZE 510
177 err_t sqlite3OsDelete(CONST_STRPTR);
178 BOOL sqlite3OsFileExists(CONST_STRPTR);
179 err_t sqlite3OsOpenReadWrite(CONST_STRPTR, OsFile*, int*);
180 err_t sqlite3OsOpenExclusive(CONST_STRPTR, OsFile*, BOOL);
181 err_t sqlite3OsOpenReadOnly(CONST_STRPTR, OsFile*);
182 err_t sqlite3OsOpenDirectory(CONST_STRPTR, OsFile*);
183 err_t sqlite3OsSyncDirectory(CONST_STRPTR);
184 err_t sqlite3OsTempFileName(char*);
185 BOOL sqlite3OsIsDirWritable(CONST_STRPTR);
186 err_t sqlite3OsClose(OsFile*);
187 err_t sqlite3OsRead(OsFile*, void*, int amt);
188 err_t sqlite3OsWrite(OsFile*, const void*, int amt);
189 err_t sqlite3OsSeek(OsFile*, i64 offset);
190 err_t sqlite3OsSync(OsFile*);
191 err_t sqlite3OsTruncate(OsFile*, i64 size);
192 err_t sqlite3OsFileSize(OsFile*, i64 *pSize);
193 char *sqlite3OsFullPathname(CONST_STRPTR);
194 err_t sqlite3OsLock(OsFile*, int);
195 err_t sqlite3OsUnlock(OsFile*, int);
196 BOOL sqlite3OsCheckReservedLock(OsFile *id);
199 /* The interface for file I/O is above. Other miscellaneous functions
200 ** are below */
202 int sqlite3OsRandomSeed(char*);
203 int sqlite3OsSleep(int ms);
204 BOOL sqlite3OsCurrentTime(double*);
205 void sqlite3OsEnterMutex(void);
206 void sqlite3OsLeaveMutex(void);
208 #endif /* _SQLITE_OS_H_ */