drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 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 | |
drh | 1ab4300 | 2002-01-14 09:28:19 +0000 | [diff] [blame^] | 20 | #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 | |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 28 | /* |
| 29 | ** A handle for an open file is stored in an OsFile object. |
| 30 | */ |
| 31 | #if OS_UNIX |
drh | ad75e98 | 2001-10-09 04:19:46 +0000 | [diff] [blame] | 32 | typedef struct OsFile OsFile; |
| 33 | struct OsFile { |
| 34 | struct lockInfo *pLock; /* Information about locks on this inode */ |
| 35 | int fd; /* The file descriptor */ |
drh | a7fcb05 | 2001-12-14 15:09:55 +0000 | [diff] [blame] | 36 | int locked; /* True if this user holds the lock */ |
drh | ad75e98 | 2001-10-09 04:19:46 +0000 | [diff] [blame] | 37 | }; |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 38 | # define SQLITE_TEMPNAME_SIZE 200 |
drh | 8cfbf08 | 2001-09-19 13:22:39 +0000 | [diff] [blame] | 39 | # if defined(HAVE_USLEEP) && HAVE_USLEEP |
| 40 | # define SQLITE_MIN_SLEEP_MS 1 |
| 41 | # else |
| 42 | # define SQLITE_MIN_SLEEP_MS 1000 |
| 43 | # endif |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 44 | #endif |
| 45 | |
| 46 | #if OS_WIN |
drh | 254cba2 | 2001-09-20 01:44:42 +0000 | [diff] [blame] | 47 | #include <windows.h> |
| 48 | #include <winbase.h> |
drh | a7fcb05 | 2001-12-14 15:09:55 +0000 | [diff] [blame] | 49 | typedef struct OsFile OsFile; |
| 50 | struct OsFile { |
| 51 | HANDLE h; |
| 52 | int locked; |
| 53 | }; |
drh | 8cfbf08 | 2001-09-19 13:22:39 +0000 | [diff] [blame] | 54 | # define SQLITE_TEMPNAME_SIZE (MAX_PATH+50) |
drh | 254cba2 | 2001-09-20 01:44:42 +0000 | [diff] [blame] | 55 | # define SQLITE_MIN_SLEEP_MS 1 |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 56 | #endif |
| 57 | |
drh | 8cfbf08 | 2001-09-19 13:22:39 +0000 | [diff] [blame] | 58 | int sqliteOsDelete(const char*); |
| 59 | int sqliteOsFileExists(const char*); |
| 60 | int sqliteOsOpenReadWrite(const char*, OsFile*, int*); |
| 61 | int sqliteOsOpenExclusive(const char*, OsFile*); |
drh | 474d3d6 | 2001-09-19 13:58:43 +0000 | [diff] [blame] | 62 | int sqliteOsOpenReadOnly(const char*, OsFile*); |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 63 | int sqliteOsTempFileName(char*); |
drh | a7fcb05 | 2001-12-14 15:09:55 +0000 | [diff] [blame] | 64 | int sqliteOsClose(OsFile*); |
| 65 | int sqliteOsRead(OsFile*, void*, int amt); |
| 66 | int sqliteOsWrite(OsFile*, const void*, int amt); |
| 67 | int sqliteOsSeek(OsFile*, int offset); |
| 68 | int sqliteOsSync(OsFile*); |
| 69 | int sqliteOsTruncate(OsFile*, int size); |
| 70 | int sqliteOsFileSize(OsFile*, int *pSize); |
| 71 | int sqliteOsReadLock(OsFile*); |
| 72 | int sqliteOsWriteLock(OsFile*); |
| 73 | int sqliteOsUnlock(OsFile*); |
drh | 8cfbf08 | 2001-09-19 13:22:39 +0000 | [diff] [blame] | 74 | int sqliteOsRandomSeed(char*); |
| 75 | int sqliteOsSleep(int ms); |
drh | b8ca307 | 2001-12-05 00:21:20 +0000 | [diff] [blame] | 76 | void sqliteOsEnterMutex(void); |
| 77 | void sqliteOsLeaveMutex(void); |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 78 | |
| 79 | |
| 80 | |
| 81 | #endif /* _SQLITE_OS_H_ */ |