monotone

monotone Mtn Source Tree

Root/sqlite/os.h

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# define _FILE_OFFSET_BITS 64
43# define _LARGEFILE_SOURCE 1
44#endif
45
46/*
47** Temporary files are named starting with this prefix followed by 16 random
48** alphanumeric characters, and no file extension. They are stored in the
49** OS's standard temporary file directory, and are deleted prior to exit.
50** If sqlite is being embedded in another program, you may wish to change the
51** prefix to reflect your program's name, so that if your program exits
52** prematurely, old temporary files can be easily identified. This can be done
53** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line.
54*/
55#ifndef TEMP_FILE_PREFIX
56# define TEMP_FILE_PREFIX "sqlite_"
57#endif
58
59/*
60** Figure out if we are dealing with Unix, Windows or MacOS.
61**
62** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
63** The MacOS build is designed to use CodeWarrior (tested with v8)
64*/
65#ifndef OS_UNIX
66# ifndef OS_WIN
67# ifndef OS_MAC
68# if defined(__MACOS__)
69# define OS_MAC 1
70# define OS_WIN 0
71# define OS_UNIX 0
72# elif defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
73# define OS_MAC 0
74# define OS_WIN 1
75# define OS_UNIX 0
76# else
77# define OS_MAC 0
78# define OS_WIN 0
79# define OS_UNIX 1
80# endif
81# else
82# define OS_WIN 0
83# define OS_UNIX 0
84# endif
85# else
86# define OS_MAC 0
87# define OS_UNIX 0
88# endif
89#else
90# define OS_MAC 0
91# define OS_WIN 0
92#endif
93
94/*
95** A handle for an open file is stored in an OsFile object.
96*/
97#if OS_UNIX
98# include <sys/types.h>
99# include <sys/stat.h>
100# include <fcntl.h>
101# include <unistd.h>
102 typedef struct OsFile OsFile;
103 struct OsFile {
104 struct lockInfo *pLock; /* Information about locks on this inode */
105 int fd; /* The file descriptor */
106 int locked; /* True if this user holds the lock */
107 };
108# define SQLITE_TEMPNAME_SIZE 200
109# if defined(HAVE_USLEEP) && HAVE_USLEEP
110# define SQLITE_MIN_SLEEP_MS 1
111# else
112# define SQLITE_MIN_SLEEP_MS 1000
113# endif
114#endif
115
116#if OS_WIN
117#include <windows.h>
118#include <winbase.h>
119 typedef struct OsFile OsFile;
120 struct OsFile {
121 HANDLE h; /* Handle for accessing the file */
122 int locked; /* 0: unlocked, <0: write lock, >0: read lock */
123 };
124# if defined(_MSC_VER) || defined(__BORLANDC__)
125 typedef __int64 off_t;
126# else
127 typedef long long off_t;
128# endif
129# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
130# define SQLITE_MIN_SLEEP_MS 1
131#endif
132
133#if OS_MAC
134# include <unistd.h>
135# include <Files.h>
136 typedef struct OsFile OsFile;
137 struct OsFile {
138 SInt16 refNum; /* Data fork/file reference number */
139 SInt16 refNumRF; /* Resource fork reference number (for locking) */
140 int locked; /* 0: unlocked, <0: write lock, >0: read lock */
141 int delOnClose; /* True if file is to be deleted on close */
142 char *pathToDel; /* Name of file to delete on close */
143 };
144# ifdef _LARGE_FILE
145 typedef SInt64 off_t;
146# else
147 typedef SInt32 off_t;
148# endif
149# define SQLITE_TEMPNAME_SIZE _MAX_PATH
150# define SQLITE_MIN_SLEEP_MS 17
151#endif
152
153int sqliteOsDelete(const char*);
154int sqliteOsFileExists(const char*);
155int sqliteOsFileRename(const char*, const char*);
156int sqliteOsOpenReadWrite(const char*, OsFile*, int*);
157int sqliteOsOpenExclusive(const char*, OsFile*, int);
158int sqliteOsOpenReadOnly(const char*, OsFile*);
159int sqliteOsTempFileName(char*);
160int sqliteOsClose(OsFile*);
161int sqliteOsRead(OsFile*, void*, int amt);
162int sqliteOsWrite(OsFile*, const void*, int amt);
163int sqliteOsSeek(OsFile*, off_t offset);
164int sqliteOsSync(OsFile*);
165int sqliteOsTruncate(OsFile*, off_t size);
166int sqliteOsFileSize(OsFile*, off_t *pSize);
167int sqliteOsReadLock(OsFile*);
168int sqliteOsWriteLock(OsFile*);
169int sqliteOsUnlock(OsFile*);
170int sqliteOsRandomSeed(char*);
171int sqliteOsSleep(int ms);
172void sqliteOsEnterMutex(void);
173void sqliteOsLeaveMutex(void);
174char *sqliteOsFullPathname(const char*);
175
176
177
178#endif /* _SQLITE_OS_H_ */

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status