source: trunk/src/3rdparty/sqlite/os.h@ 205

Last change on this file since 205 was 205, checked in by rudi, 14 years ago

Added SQLite 2.8.17 sources. This allows to build at least one of the sql drivers / plugins.

File size: 6.9 KB
Line 
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.
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
20/*
21** Helpful hint: To get this to compile on HP/UX, add -D_INCLUDE_POSIX_SOURCE
22** to the compiler command line.
23*/
24
25/*
26** These #defines should enable >2GB file support on Posix if the
27** underlying operating system supports it. If the OS lacks
28** large file support, or if the OS is windows, these should be no-ops.
29**
30** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
31** on the compiler command line. This is necessary if you are compiling
32** on a recent machine (ex: RedHat 7.2) but you want your code to work
33** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2
34** without this option, LFS is enable. But LFS does not exist in the kernel
35** in RedHat 6.0, so the code won't work. Hence, for maximum binary
36** portability you should omit LFS.
37**
38** Similar is true for MacOS. LFS is only supported on MacOS 9 and later.
39*/
40#ifndef SQLITE_DISABLE_LFS
41# define _LARGE_FILE 1
42# ifndef _FILE_OFFSET_BITS
43# define _FILE_OFFSET_BITS 64
44# endif
45# define _LARGEFILE_SOURCE 1
46#endif
47
48/*
49** Temporary files are named starting with this prefix followed by 16 random
50** alphanumeric characters, and no file extension. They are stored in the
51** OS's standard temporary file directory, and are deleted prior to exit.
52** If sqlite is being embedded in another program, you may wish to change the
53** prefix to reflect your program's name, so that if your program exits
54** prematurely, old temporary files can be easily identified. This can be done
55** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line.
56*/
57#ifndef TEMP_FILE_PREFIX
58# define TEMP_FILE_PREFIX "sqlite_"
59#endif
60
61/*
62** Figure out if we are dealing with Unix, Windows or MacOS.
63**
64** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
65** The MacOS build is designed to use CodeWarrior (tested with v8)
66*/
67#ifndef OS_UNIX
68# ifndef OS_WIN
69# ifndef OS_MAC
70# ifndef OS_OS2
71# if defined(__MACOS__)
72# define OS_MAC 1
73# define OS_WIN 0
74# define OS_OS2 0
75# define OS_UNIX 0
76# elif defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
77# define OS_MAC 0
78# define OS_WIN 1
79# define OS_OS2 0
80# define OS_UNIX 0
81# elif defined(__EMX__)
82# define OS_MAC 0
83# define OS_WIN 0
84# define OS_OS2 1
85# define OS_UNIX 0
86# else
87# define OS_MAC 0
88# define OS_WIN 0
89# define OS_OS2 0
90# define OS_UNIX 1
91# endif
92# else
93# define OS_MAC 0
94# define OS_WIN 0
95# define OS_UNIX 0
96# endif
97# else
98# define OS_WIN 0
99# define OS_OS2 0
100# define OS_UNIX 0
101# endif
102# else
103# define OS_MAC 0
104# define OS_OS2 0
105# define OS_UNIX 0
106# endif
107#else
108# define OS_MAC 0
109# ifndef OS_WIN
110# define OS_WIN 0
111# endif
112# define OS_OS2 0
113#endif
114
115/*
116** A handle for an open file is stored in an OsFile object.
117*/
118#if OS_UNIX
119# include <sys/types.h>
120# include <sys/stat.h>
121# include <fcntl.h>
122# include <unistd.h>
123 typedef struct OsFile OsFile;
124 struct OsFile {
125 struct openCnt *pOpen; /* Info about all open fd's on this inode */
126 struct lockInfo *pLock; /* Info about locks on this inode */
127 int fd; /* The file descriptor */
128 int locked; /* True if this instance holds the lock */
129 int dirfd; /* File descriptor for the directory */
130 };
131# define SQLITE_TEMPNAME_SIZE 200
132# if defined(HAVE_USLEEP) && HAVE_USLEEP
133# define SQLITE_MIN_SLEEP_MS 1
134# else
135# define SQLITE_MIN_SLEEP_MS 1000
136# endif
137#endif
138
139#if OS_WIN
140#include <windows.h>
141#include <winbase.h>
142 typedef struct OsFile OsFile;
143 struct OsFile {
144 HANDLE h; /* Handle for accessing the file */
145 int locked; /* 0: unlocked, <0: write lock, >0: read lock */
146 };
147# if defined(_MSC_VER) || defined(__BORLANDC__)
148 typedef __int64 off_t;
149# else
150# if !defined(_CYGWIN_TYPES_H)
151 typedef long long off_t;
152# if defined(__MINGW32__)
153# define _OFF_T_
154# endif
155# endif
156# endif
157# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
158# define SQLITE_MIN_SLEEP_MS 1
159#endif
160
161#if OS_MAC
162# include <unistd.h>
163# include <Files.h>
164 typedef struct OsFile OsFile;
165 struct OsFile {
166 SInt16 refNum; /* Data fork/file reference number */
167 SInt16 refNumRF; /* Resource fork reference number (for locking) */
168 int locked; /* 0: unlocked, <0: write lock, >0: read lock */
169 int delOnClose; /* True if file is to be deleted on close */
170 char *pathToDel; /* Name of file to delete on close */
171 };
172# ifdef _LARGE_FILE
173 typedef SInt64 off_t;
174# else
175 typedef SInt32 off_t;
176# endif
177# define SQLITE_TEMPNAME_SIZE _MAX_PATH
178# define SQLITE_MIN_SLEEP_MS 17
179#endif
180
181#if OS_OS2
182# include <sys/types.h>
183# include <sys/stat.h>
184# include <fcntl.h>
185# include <unistd.h>
186 typedef struct OsFile OsFile;
187 struct OsFile {
188 unsigned long fd; /* The file descriptor (LHANDLE) */
189 int locked; /* True if this user holds the lock */
190 int delOnClose; /* True if file is to be deleted on close */
191 char *pathToDel; /* Name of file to delete on close */
192 };
193# define SQLITE_TEMPNAME_SIZE 200
194# define SQLITE_MIN_SLEEP_MS 1
195#endif
196
197int sqliteOsDelete(const char*);
198int sqliteOsFileExists(const char*);
199int sqliteOsFileRename(const char*, const char*);
200int sqliteOsOpenReadWrite(const char*, OsFile*, int*);
201int sqliteOsOpenExclusive(const char*, OsFile*, int);
202int sqliteOsOpenReadOnly(const char*, OsFile*);
203int sqliteOsOpenDirectory(const char*, OsFile*);
204int sqliteOsTempFileName(char*);
205int sqliteOsClose(OsFile*);
206int sqliteOsRead(OsFile*, void*, int amt);
207int sqliteOsWrite(OsFile*, const void*, int amt);
208int sqliteOsSeek(OsFile*, off_t offset);
209int sqliteOsSync(OsFile*);
210int sqliteOsTruncate(OsFile*, off_t size);
211int sqliteOsFileSize(OsFile*, off_t *pSize);
212int sqliteOsReadLock(OsFile*);
213int sqliteOsWriteLock(OsFile*);
214int sqliteOsUnlock(OsFile*);
215int sqliteOsRandomSeed(char*);
216int sqliteOsSleep(int ms);
217int sqliteOsCurrentTime(double*);
218void sqliteOsEnterMutex(void);
219void sqliteOsLeaveMutex(void);
220char *sqliteOsFullPathname(const char*);
221
222
223
224#endif /* _SQLITE_OS_H_ */
Note: See TracBrowser for help on using the repository browser.