extensions/sqlite/sqlite-source/os.h
branchrefac-jit
changeset 2284 026da5437111
parent 2192 7602d7fb60d9
child 2288 15c77b21589a
     1.1 --- a/extensions/sqlite/sqlite-source/os.h	Fri Jul 11 06:51:21 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,284 +0,0 @@
     1.4 -/*
     1.5 -** 2001 September 16
     1.6 -**
     1.7 -** The author disclaims copyright to this source code.  In place of
     1.8 -** a legal notice, here is a blessing:
     1.9 -**
    1.10 -**    May you do good and not evil.
    1.11 -**    May you find forgiveness for yourself and forgive others.
    1.12 -**    May you share freely, never taking more than you give.
    1.13 -**
    1.14 -******************************************************************************
    1.15 -**
    1.16 -** This header file (together with is companion C source-code file
    1.17 -** "os.c") attempt to abstract the underlying operating system so that
    1.18 -** the SQLite library will work on both POSIX and windows systems.
    1.19 -**
    1.20 -** This header file is #include-ed by sqliteInt.h and thus ends up
    1.21 -** being included by every source file.
    1.22 -*/
    1.23 -#ifndef _SQLITE_OS_H_
    1.24 -#define _SQLITE_OS_H_
    1.25 -
    1.26 -/*
    1.27 -** Figure out if we are dealing with Unix, Windows, or some other
    1.28 -** operating system.  After the following block of preprocess macros,
    1.29 -** all of OS_UNIX, OS_WIN, OS_OS2, and OS_OTHER will defined to either
    1.30 -** 1 or 0.  One of the four will be 1.  The other three will be 0.
    1.31 -*/
    1.32 -#if defined(OS_OTHER)
    1.33 -# if OS_OTHER==1
    1.34 -#   undef OS_UNIX
    1.35 -#   define OS_UNIX 0
    1.36 -#   undef OS_WIN
    1.37 -#   define OS_WIN 0
    1.38 -#   undef OS_OS2
    1.39 -#   define OS_OS2 0
    1.40 -# else
    1.41 -#   undef OS_OTHER
    1.42 -# endif
    1.43 -#endif
    1.44 -#if !defined(OS_UNIX) && !defined(OS_OTHER)
    1.45 -# define OS_OTHER 0
    1.46 -# ifndef OS_WIN
    1.47 -#   if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
    1.48 -#     define OS_WIN 1
    1.49 -#     define OS_UNIX 0
    1.50 -#     define OS_OS2 0
    1.51 -#   elif defined(__EMX__) || defined(_OS2) || defined(OS2) || defined(_OS2_) || defined(__OS2__)
    1.52 -#     define OS_WIN 0
    1.53 -#     define OS_UNIX 0
    1.54 -#     define OS_OS2 1
    1.55 -#   else
    1.56 -#     define OS_WIN 0
    1.57 -#     define OS_UNIX 1
    1.58 -#     define OS_OS2 0
    1.59 -#  endif
    1.60 -# else
    1.61 -#  define OS_UNIX 0
    1.62 -#  define OS_OS2 0
    1.63 -# endif
    1.64 -#else
    1.65 -# ifndef OS_WIN
    1.66 -#  define OS_WIN 0
    1.67 -# endif
    1.68 -#endif
    1.69 -
    1.70 -
    1.71 -
    1.72 -/*
    1.73 -** Define the maximum size of a temporary filename
    1.74 -*/
    1.75 -#if OS_WIN
    1.76 -# include <windows.h>
    1.77 -# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
    1.78 -#elif OS_OS2
    1.79 -# if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_MEMORY)
    1.80 -#  include <os2safe.h> /* has to be included before os2.h for linking to work */
    1.81 -# endif
    1.82 -# define INCL_DOSDATETIME
    1.83 -# define INCL_DOSFILEMGR
    1.84 -# define INCL_DOSERRORS
    1.85 -# define INCL_DOSMISC
    1.86 -# define INCL_DOSPROCESS
    1.87 -# define INCL_DOSMODULEMGR
    1.88 -# include <os2.h>
    1.89 -# define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP)
    1.90 -#else
    1.91 -# define SQLITE_TEMPNAME_SIZE 200
    1.92 -#endif
    1.93 -
    1.94 -/* If the SET_FULLSYNC macro is not defined above, then make it
    1.95 -** a no-op
    1.96 -*/
    1.97 -#ifndef SET_FULLSYNC
    1.98 -# define SET_FULLSYNC(x,y)
    1.99 -#endif
   1.100 -
   1.101 -/*
   1.102 -** The default size of a disk sector
   1.103 -*/
   1.104 -#ifndef SQLITE_DEFAULT_SECTOR_SIZE
   1.105 -# define SQLITE_DEFAULT_SECTOR_SIZE 512
   1.106 -#endif
   1.107 -
   1.108 -/*
   1.109 -** Temporary files are named starting with this prefix followed by 16 random
   1.110 -** alphanumeric characters, and no file extension. They are stored in the
   1.111 -** OS's standard temporary file directory, and are deleted prior to exit.
   1.112 -** If sqlite is being embedded in another program, you may wish to change the
   1.113 -** prefix to reflect your program's name, so that if your program exits
   1.114 -** prematurely, old temporary files can be easily identified. This can be done
   1.115 -** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line.
   1.116 -**
   1.117 -** 2006-10-31:  The default prefix used to be "sqlite_".  But then
   1.118 -** Mcafee started using SQLite in their anti-virus product and it
   1.119 -** started putting files with the "sqlite" name in the c:/temp folder.
   1.120 -** This annoyed many windows users.  Those users would then do a 
   1.121 -** Google search for "sqlite", find the telephone numbers of the
   1.122 -** developers and call to wake them up at night and complain.
   1.123 -** For this reason, the default name prefix is changed to be "sqlite" 
   1.124 -** spelled backwards.  So the temp files are still identified, but
   1.125 -** anybody smart enough to figure out the code is also likely smart
   1.126 -** enough to know that calling the developer will not help get rid
   1.127 -** of the file.
   1.128 -*/
   1.129 -#ifndef SQLITE_TEMP_FILE_PREFIX
   1.130 -# define SQLITE_TEMP_FILE_PREFIX "etilqs_"
   1.131 -#endif
   1.132 -
   1.133 -/*
   1.134 -** If using an alternative OS interface, then we must have an "os_other.h"
   1.135 -** header file available for that interface.  Presumably the "os_other.h"
   1.136 -** header file contains #defines similar to those above.
   1.137 -*/
   1.138 -#if OS_OTHER
   1.139 -# include "os_other.h"
   1.140 -#endif
   1.141 -
   1.142 -
   1.143 -/*
   1.144 -** The following values may be passed as the second argument to
   1.145 -** sqlite3OsLock(). The various locks exhibit the following semantics:
   1.146 -**
   1.147 -** SHARED:    Any number of processes may hold a SHARED lock simultaneously.
   1.148 -** RESERVED:  A single process may hold a RESERVED lock on a file at
   1.149 -**            any time. Other processes may hold and obtain new SHARED locks.
   1.150 -** PENDING:   A single process may hold a PENDING lock on a file at
   1.151 -**            any one time. Existing SHARED locks may persist, but no new
   1.152 -**            SHARED locks may be obtained by other processes.
   1.153 -** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
   1.154 -**
   1.155 -** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
   1.156 -** process that requests an EXCLUSIVE lock may actually obtain a PENDING
   1.157 -** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
   1.158 -** sqlite3OsLock().
   1.159 -*/
   1.160 -#define NO_LOCK         0
   1.161 -#define SHARED_LOCK     1
   1.162 -#define RESERVED_LOCK   2
   1.163 -#define PENDING_LOCK    3
   1.164 -#define EXCLUSIVE_LOCK  4
   1.165 -
   1.166 -/*
   1.167 -** File Locking Notes:  (Mostly about windows but also some info for Unix)
   1.168 -**
   1.169 -** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
   1.170 -** those functions are not available.  So we use only LockFile() and
   1.171 -** UnlockFile().
   1.172 -**
   1.173 -** LockFile() prevents not just writing but also reading by other processes.
   1.174 -** A SHARED_LOCK is obtained by locking a single randomly-chosen 
   1.175 -** byte out of a specific range of bytes. The lock byte is obtained at 
   1.176 -** random so two separate readers can probably access the file at the 
   1.177 -** same time, unless they are unlucky and choose the same lock byte.
   1.178 -** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
   1.179 -** There can only be one writer.  A RESERVED_LOCK is obtained by locking
   1.180 -** a single byte of the file that is designated as the reserved lock byte.
   1.181 -** A PENDING_LOCK is obtained by locking a designated byte different from
   1.182 -** the RESERVED_LOCK byte.
   1.183 -**
   1.184 -** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
   1.185 -** which means we can use reader/writer locks.  When reader/writer locks
   1.186 -** are used, the lock is placed on the same range of bytes that is used
   1.187 -** for probabilistic locking in Win95/98/ME.  Hence, the locking scheme
   1.188 -** will support two or more Win95 readers or two or more WinNT readers.
   1.189 -** But a single Win95 reader will lock out all WinNT readers and a single
   1.190 -** WinNT reader will lock out all other Win95 readers.
   1.191 -**
   1.192 -** The following #defines specify the range of bytes used for locking.
   1.193 -** SHARED_SIZE is the number of bytes available in the pool from which
   1.194 -** a random byte is selected for a shared lock.  The pool of bytes for
   1.195 -** shared locks begins at SHARED_FIRST. 
   1.196 -**
   1.197 -** These #defines are available in sqlite_aux.h so that adaptors for
   1.198 -** connecting SQLite to other operating systems can use the same byte
   1.199 -** ranges for locking.  In particular, the same locking strategy and
   1.200 -** byte ranges are used for Unix.  This leaves open the possiblity of having
   1.201 -** clients on win95, winNT, and unix all talking to the same shared file
   1.202 -** and all locking correctly.  To do so would require that samba (or whatever
   1.203 -** tool is being used for file sharing) implements locks correctly between
   1.204 -** windows and unix.  I'm guessing that isn't likely to happen, but by
   1.205 -** using the same locking range we are at least open to the possibility.
   1.206 -**
   1.207 -** Locking in windows is manditory.  For this reason, we cannot store
   1.208 -** actual data in the bytes used for locking.  The pager never allocates
   1.209 -** the pages involved in locking therefore.  SHARED_SIZE is selected so
   1.210 -** that all locks will fit on a single page even at the minimum page size.
   1.211 -** PENDING_BYTE defines the beginning of the locks.  By default PENDING_BYTE
   1.212 -** is set high so that we don't have to allocate an unused page except
   1.213 -** for very large databases.  But one should test the page skipping logic 
   1.214 -** by setting PENDING_BYTE low and running the entire regression suite.
   1.215 -**
   1.216 -** Changing the value of PENDING_BYTE results in a subtly incompatible
   1.217 -** file format.  Depending on how it is changed, you might not notice
   1.218 -** the incompatibility right away, even running a full regression test.
   1.219 -** The default location of PENDING_BYTE is the first byte past the
   1.220 -** 1GB boundary.
   1.221 -**
   1.222 -*/
   1.223 -#ifndef SQLITE_TEST
   1.224 -#define PENDING_BYTE      0x40000000  /* First byte past the 1GB boundary */
   1.225 -#else
   1.226 -extern unsigned int sqlite3_pending_byte;
   1.227 -#define PENDING_BYTE sqlite3_pending_byte
   1.228 -#endif
   1.229 -
   1.230 -#define RESERVED_BYTE     (PENDING_BYTE+1)
   1.231 -#define SHARED_FIRST      (PENDING_BYTE+2)
   1.232 -#define SHARED_SIZE       510
   1.233 -
   1.234 -/* 
   1.235 -** Functions for accessing sqlite3_file methods 
   1.236 -*/
   1.237 -int sqlite3OsClose(sqlite3_file*);
   1.238 -int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
   1.239 -int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
   1.240 -int sqlite3OsTruncate(sqlite3_file*, i64 size);
   1.241 -int sqlite3OsSync(sqlite3_file*, int);
   1.242 -int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
   1.243 -int sqlite3OsLock(sqlite3_file*, int);
   1.244 -int sqlite3OsUnlock(sqlite3_file*, int);
   1.245 -int sqlite3OsCheckReservedLock(sqlite3_file *id);
   1.246 -int sqlite3OsFileControl(sqlite3_file*,int,void*);
   1.247 -int sqlite3OsSectorSize(sqlite3_file *id);
   1.248 -int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
   1.249 -
   1.250 -/* 
   1.251 -** Functions for accessing sqlite3_vfs methods 
   1.252 -*/
   1.253 -int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *);
   1.254 -int sqlite3OsDelete(sqlite3_vfs *, const char *, int);
   1.255 -int sqlite3OsAccess(sqlite3_vfs *, const char *, int);
   1.256 -int sqlite3OsGetTempname(sqlite3_vfs *, int, char *);
   1.257 -int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *);
   1.258 -void *sqlite3OsDlOpen(sqlite3_vfs *, const char *);
   1.259 -void sqlite3OsDlError(sqlite3_vfs *, int, char *);
   1.260 -void *sqlite3OsDlSym(sqlite3_vfs *, void *, const char *);
   1.261 -void sqlite3OsDlClose(sqlite3_vfs *, void *);
   1.262 -int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
   1.263 -int sqlite3OsSleep(sqlite3_vfs *, int);
   1.264 -int sqlite3OsCurrentTime(sqlite3_vfs *, double*);
   1.265 -
   1.266 -/*
   1.267 -** Convenience functions for opening and closing files using 
   1.268 -** sqlite3_malloc() to obtain space for the file-handle structure.
   1.269 -*/
   1.270 -int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
   1.271 -int sqlite3OsCloseFree(sqlite3_file *);
   1.272 -
   1.273 -/*
   1.274 -** Each OS-specific backend defines an instance of the following
   1.275 -** structure for returning a pointer to its sqlite3_vfs.  If OS_OTHER
   1.276 -** is defined (meaning that the application-defined OS interface layer
   1.277 -** is used) then there is no default VFS.   The application must
   1.278 -** register one or more VFS structures using sqlite3_vfs_register()
   1.279 -** before attempting to use SQLite.
   1.280 -*/
   1.281 -#if OS_UNIX || OS_WIN || OS_OS2
   1.282 -sqlite3_vfs *sqlite3OsDefaultVfs(void);
   1.283 -#else
   1.284 -# define sqlite3OsDefaultVfs(X) 0
   1.285 -#endif
   1.286 -
   1.287 -#endif /* _SQLITE_OS_H_ */