blob: 0985af4c7284f778fef3691ca7a91bf922ead75d [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
drh27a32202002-03-20 00:00:29 +000020#ifndef OS_UNIX
21# ifndef OS_WIN
22# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
23# define OS_WIN 1
24# define OS_UNIX 0
25# else
26# define OS_WIN 0
27# define OS_UNIX 1
28# endif
29# else
30# define OS_UNIX 0
31# endif
32#endif
33#ifndef OS_WIN
34# define OS_WIN 0
drh1ab43002002-01-14 09:28:19 +000035#endif
36
drhe3c41372001-09-17 20:25:58 +000037/*
38** A handle for an open file is stored in an OsFile object.
39*/
40#if OS_UNIX
drh20e9ab12002-11-06 00:59:44 +000041# include <sys/types.h>
42# include <sys/stat.h>
43# include <fcntl.h>
44# include <unistd.h>
drhad75e982001-10-09 04:19:46 +000045 typedef struct OsFile OsFile;
46 struct OsFile {
47 struct lockInfo *pLock; /* Information about locks on this inode */
48 int fd; /* The file descriptor */
drha7fcb052001-12-14 15:09:55 +000049 int locked; /* True if this user holds the lock */
drhad75e982001-10-09 04:19:46 +000050 };
drhe3c41372001-09-17 20:25:58 +000051# define SQLITE_TEMPNAME_SIZE 200
drh8cfbf082001-09-19 13:22:39 +000052# if defined(HAVE_USLEEP) && HAVE_USLEEP
53# define SQLITE_MIN_SLEEP_MS 1
54# else
55# define SQLITE_MIN_SLEEP_MS 1000
56# endif
drhe3c41372001-09-17 20:25:58 +000057#endif
58
59#if OS_WIN
drh254cba22001-09-20 01:44:42 +000060#include <windows.h>
61#include <winbase.h>
drha7fcb052001-12-14 15:09:55 +000062 typedef struct OsFile OsFile;
63 struct OsFile {
drhd1efac52002-08-14 12:56:54 +000064 HANDLE h; /* Handle for accessing the file */
65 int locked; /* 0: unlocked, <0: write lock, >0: read lock */
drha7fcb052001-12-14 15:09:55 +000066 };
drh28be87c2002-11-05 23:03:02 +000067 typedef int off_t;
drh8cfbf082001-09-19 13:22:39 +000068# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
drh254cba22001-09-20 01:44:42 +000069# define SQLITE_MIN_SLEEP_MS 1
drhe3c41372001-09-17 20:25:58 +000070#endif
71
drh8cfbf082001-09-19 13:22:39 +000072int sqliteOsDelete(const char*);
73int sqliteOsFileExists(const char*);
74int sqliteOsOpenReadWrite(const char*, OsFile*, int*);
drhfa86c412002-02-02 15:01:15 +000075int sqliteOsOpenExclusive(const char*, OsFile*, int);
drh474d3d62001-09-19 13:58:43 +000076int sqliteOsOpenReadOnly(const char*, OsFile*);
drhe3c41372001-09-17 20:25:58 +000077int sqliteOsTempFileName(char*);
drha7fcb052001-12-14 15:09:55 +000078int sqliteOsClose(OsFile*);
79int sqliteOsRead(OsFile*, void*, int amt);
80int sqliteOsWrite(OsFile*, const void*, int amt);
drh28be87c2002-11-05 23:03:02 +000081int sqliteOsSeek(OsFile*, off_t offset);
drha7fcb052001-12-14 15:09:55 +000082int sqliteOsSync(OsFile*);
drh28be87c2002-11-05 23:03:02 +000083int sqliteOsTruncate(OsFile*, off_t size);
84int sqliteOsFileSize(OsFile*, off_t *pSize);
drha7fcb052001-12-14 15:09:55 +000085int sqliteOsReadLock(OsFile*);
86int sqliteOsWriteLock(OsFile*);
87int sqliteOsUnlock(OsFile*);
drh8cfbf082001-09-19 13:22:39 +000088int sqliteOsRandomSeed(char*);
89int sqliteOsSleep(int ms);
drhb8ca3072001-12-05 00:21:20 +000090void sqliteOsEnterMutex(void);
91void sqliteOsLeaveMutex(void);
drhe3c41372001-09-17 20:25:58 +000092
93
94
95#endif /* _SQLITE_OS_H_ */