blob: 8d2238bae7747cc53d43d111894550bc90f18884 [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
drh1ab43002002-01-14 09:28:19 +000020#ifdef WIN32
21# define OS_WIN 1
22# undef OS_UNIX
23#else
24# define OS_UNIX 1
25# undef OS_WIN
26#endif
27
drhe3c41372001-09-17 20:25:58 +000028/*
29** A handle for an open file is stored in an OsFile object.
30*/
31#if OS_UNIX
drhad75e982001-10-09 04:19:46 +000032 typedef struct OsFile OsFile;
33 struct OsFile {
34 struct lockInfo *pLock; /* Information about locks on this inode */
35 int fd; /* The file descriptor */
drha7fcb052001-12-14 15:09:55 +000036 int locked; /* True if this user holds the lock */
drhad75e982001-10-09 04:19:46 +000037 };
drhe3c41372001-09-17 20:25:58 +000038# define SQLITE_TEMPNAME_SIZE 200
drh8cfbf082001-09-19 13:22:39 +000039# if defined(HAVE_USLEEP) && HAVE_USLEEP
40# define SQLITE_MIN_SLEEP_MS 1
41# else
42# define SQLITE_MIN_SLEEP_MS 1000
43# endif
drhe3c41372001-09-17 20:25:58 +000044#endif
45
46#if OS_WIN
drh254cba22001-09-20 01:44:42 +000047#include <windows.h>
48#include <winbase.h>
drha7fcb052001-12-14 15:09:55 +000049 typedef struct OsFile OsFile;
50 struct OsFile {
51 HANDLE h;
52 int locked;
53 };
drh8cfbf082001-09-19 13:22:39 +000054# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
drh254cba22001-09-20 01:44:42 +000055# define SQLITE_MIN_SLEEP_MS 1
drhe3c41372001-09-17 20:25:58 +000056#endif
57
drh8cfbf082001-09-19 13:22:39 +000058int sqliteOsDelete(const char*);
59int sqliteOsFileExists(const char*);
60int sqliteOsOpenReadWrite(const char*, OsFile*, int*);
61int sqliteOsOpenExclusive(const char*, OsFile*);
drh474d3d62001-09-19 13:58:43 +000062int sqliteOsOpenReadOnly(const char*, OsFile*);
drhe3c41372001-09-17 20:25:58 +000063int sqliteOsTempFileName(char*);
drha7fcb052001-12-14 15:09:55 +000064int sqliteOsClose(OsFile*);
65int sqliteOsRead(OsFile*, void*, int amt);
66int sqliteOsWrite(OsFile*, const void*, int amt);
67int sqliteOsSeek(OsFile*, int offset);
68int sqliteOsSync(OsFile*);
69int sqliteOsTruncate(OsFile*, int size);
70int sqliteOsFileSize(OsFile*, int *pSize);
71int sqliteOsReadLock(OsFile*);
72int sqliteOsWriteLock(OsFile*);
73int sqliteOsUnlock(OsFile*);
drh8cfbf082001-09-19 13:22:39 +000074int sqliteOsRandomSeed(char*);
75int sqliteOsSleep(int ms);
drhb8ca3072001-12-05 00:21:20 +000076void sqliteOsEnterMutex(void);
77void sqliteOsLeaveMutex(void);
drhe3c41372001-09-17 20:25:58 +000078
79
80
81#endif /* _SQLITE_OS_H_ */