blob: 44764a456d6c1c38e83dae6768f95c6cd7d547b6 [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/*
21** These #defines should enable >2GB file support on Posix if the
22** underlying operating system supports it. If the OS lacks
23** large file support, or if the OS is windows, these should be no-ops.
24*/
25#define _LARGE_FILE 1
26#define _FILE_OFFSET_BITS 64
27#define _LARGEFILE_SOURCE 1
28
29/*
30** Figure out if we are dealing with Unix or Windows.
31*/
drh27a32202002-03-20 00:00:29 +000032#ifndef OS_UNIX
33# ifndef OS_WIN
34# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
35# define OS_WIN 1
36# define OS_UNIX 0
37# else
38# define OS_WIN 0
39# define OS_UNIX 1
40# endif
41# else
42# define OS_UNIX 0
43# endif
44#endif
45#ifndef OS_WIN
46# define OS_WIN 0
drh1ab43002002-01-14 09:28:19 +000047#endif
48
drhe3c41372001-09-17 20:25:58 +000049/*
50** A handle for an open file is stored in an OsFile object.
51*/
52#if OS_UNIX
drh20e9ab12002-11-06 00:59:44 +000053# include <sys/types.h>
54# include <sys/stat.h>
55# include <fcntl.h>
56# include <unistd.h>
drhad75e982001-10-09 04:19:46 +000057 typedef struct OsFile OsFile;
58 struct OsFile {
59 struct lockInfo *pLock; /* Information about locks on this inode */
60 int fd; /* The file descriptor */
drha7fcb052001-12-14 15:09:55 +000061 int locked; /* True if this user holds the lock */
drhad75e982001-10-09 04:19:46 +000062 };
drhe3c41372001-09-17 20:25:58 +000063# define SQLITE_TEMPNAME_SIZE 200
drh8cfbf082001-09-19 13:22:39 +000064# if defined(HAVE_USLEEP) && HAVE_USLEEP
65# define SQLITE_MIN_SLEEP_MS 1
66# else
67# define SQLITE_MIN_SLEEP_MS 1000
68# endif
drhe3c41372001-09-17 20:25:58 +000069#endif
70
71#if OS_WIN
drh254cba22001-09-20 01:44:42 +000072#include <windows.h>
73#include <winbase.h>
drha7fcb052001-12-14 15:09:55 +000074 typedef struct OsFile OsFile;
75 struct OsFile {
drhd1efac52002-08-14 12:56:54 +000076 HANDLE h; /* Handle for accessing the file */
77 int locked; /* 0: unlocked, <0: write lock, >0: read lock */
drha7fcb052001-12-14 15:09:55 +000078 };
drh829e8022002-11-06 14:08:11 +000079# ifdef _MSC_VER
80 typedef __int64 off_t;
81# else
82 typedef long long off_t;
83# endif
drh8cfbf082001-09-19 13:22:39 +000084# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
drh254cba22001-09-20 01:44:42 +000085# define SQLITE_MIN_SLEEP_MS 1
drhe3c41372001-09-17 20:25:58 +000086#endif
87
drh8cfbf082001-09-19 13:22:39 +000088int sqliteOsDelete(const char*);
89int sqliteOsFileExists(const char*);
90int sqliteOsOpenReadWrite(const char*, OsFile*, int*);
drhfa86c412002-02-02 15:01:15 +000091int sqliteOsOpenExclusive(const char*, OsFile*, int);
drh474d3d62001-09-19 13:58:43 +000092int sqliteOsOpenReadOnly(const char*, OsFile*);
drhe3c41372001-09-17 20:25:58 +000093int sqliteOsTempFileName(char*);
drha7fcb052001-12-14 15:09:55 +000094int sqliteOsClose(OsFile*);
95int sqliteOsRead(OsFile*, void*, int amt);
96int sqliteOsWrite(OsFile*, const void*, int amt);
drh28be87c2002-11-05 23:03:02 +000097int sqliteOsSeek(OsFile*, off_t offset);
drha7fcb052001-12-14 15:09:55 +000098int sqliteOsSync(OsFile*);
drh28be87c2002-11-05 23:03:02 +000099int sqliteOsTruncate(OsFile*, off_t size);
100int sqliteOsFileSize(OsFile*, off_t *pSize);
drha7fcb052001-12-14 15:09:55 +0000101int sqliteOsReadLock(OsFile*);
102int sqliteOsWriteLock(OsFile*);
103int sqliteOsUnlock(OsFile*);
drh8cfbf082001-09-19 13:22:39 +0000104int sqliteOsRandomSeed(char*);
105int sqliteOsSleep(int ms);
drhb8ca3072001-12-05 00:21:20 +0000106void sqliteOsEnterMutex(void);
107void sqliteOsLeaveMutex(void);
drhe3c41372001-09-17 20:25:58 +0000108
109
110
111#endif /* _SQLITE_OS_H_ */