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 | 829e802 | 2002-11-06 14:08:11 +0000 | [diff] [blame] | 20 | /* |
drh | 820f381 | 2003-01-08 13:02:52 +0000 | [diff] [blame] | 21 | ** Figure out if we are dealing with Unix, Windows or MacOS. |
| 22 | ** |
| 23 | ** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix. |
| 24 | ** The MacOS build is designed to use CodeWarrior (tested with v8) |
drh | 829e802 | 2002-11-06 14:08:11 +0000 | [diff] [blame] | 25 | */ |
drh | 27a3220 | 2002-03-20 00:00:29 +0000 | [diff] [blame] | 26 | #ifndef OS_UNIX |
| 27 | # ifndef OS_WIN |
drh | 820f381 | 2003-01-08 13:02:52 +0000 | [diff] [blame] | 28 | # ifndef OS_MAC |
| 29 | # if defined(__MACOS__) |
| 30 | # define OS_MAC 1 |
| 31 | # define OS_WIN 0 |
| 32 | # define OS_UNIX 0 |
| 33 | # elif defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__) |
| 34 | # define OS_MAC 0 |
| 35 | # define OS_WIN 1 |
| 36 | # define OS_UNIX 0 |
| 37 | # else |
| 38 | # define OS_MAC 0 |
| 39 | # define OS_WIN 0 |
| 40 | # define OS_UNIX 1 |
| 41 | # endif |
drh | 27a3220 | 2002-03-20 00:00:29 +0000 | [diff] [blame] | 42 | # else |
| 43 | # define OS_WIN 0 |
drh | 820f381 | 2003-01-08 13:02:52 +0000 | [diff] [blame] | 44 | # define OS_UNIX 0 |
drh | 27a3220 | 2002-03-20 00:00:29 +0000 | [diff] [blame] | 45 | # endif |
| 46 | # else |
drh | 820f381 | 2003-01-08 13:02:52 +0000 | [diff] [blame] | 47 | # define OS_MAC 0 |
drh | 27a3220 | 2002-03-20 00:00:29 +0000 | [diff] [blame] | 48 | # define OS_UNIX 0 |
| 49 | # endif |
drh | 820f381 | 2003-01-08 13:02:52 +0000 | [diff] [blame] | 50 | #else |
| 51 | # define OS_MAC 0 |
drh | e5e3760 | 2003-08-16 13:10:51 +0000 | [diff] [blame] | 52 | # ifndef OS_WIN |
| 53 | # define OS_WIN 0 |
| 54 | # endif |
drh | 1ab4300 | 2002-01-14 09:28:19 +0000 | [diff] [blame] | 55 | #endif |
| 56 | |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 57 | /* |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame^] | 58 | ** Invoke the appropriate operating-system specific header file. |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 59 | */ |
| 60 | #if OS_UNIX |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame^] | 61 | # include "os_unix.h" |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 62 | #endif |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 63 | #if OS_WIN |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame^] | 64 | # include "os_win.h" |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 65 | #endif |
drh | 820f381 | 2003-01-08 13:02:52 +0000 | [diff] [blame] | 66 | #if OS_MAC |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame^] | 67 | # include "os_mac.h" |
drh | 820f381 | 2003-01-08 13:02:52 +0000 | [diff] [blame] | 68 | #endif |
| 69 | |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 70 | /* |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame^] | 71 | ** Temporary files are named starting with this prefix followed by 16 random |
| 72 | ** alphanumeric characters, and no file extension. They are stored in the |
| 73 | ** OS's standard temporary file directory, and are deleted prior to exit. |
| 74 | ** If sqlite is being embedded in another program, you may wish to change the |
| 75 | ** prefix to reflect your program's name, so that if your program exits |
| 76 | ** prematurely, old temporary files can be easily identified. This can be done |
| 77 | ** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line. |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 78 | */ |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame^] | 79 | #ifndef TEMP_FILE_PREFIX |
| 80 | # define TEMP_FILE_PREFIX "sqlite_" |
| 81 | #endif |
| 82 | |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 83 | |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 84 | int sqlite3OsDelete(const char*); |
| 85 | int sqlite3OsFileExists(const char*); |
drh | 001bbcb | 2003-03-19 03:14:00 +0000 | [diff] [blame] | 86 | int sqliteOsFileRename(const char*, const char*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 87 | int sqlite3OsOpenReadWrite(const char*, OsFile*, int*); |
| 88 | int sqlite3OsOpenExclusive(const char*, OsFile*, int); |
| 89 | int sqlite3OsOpenReadOnly(const char*, OsFile*); |
| 90 | int sqlite3OsOpenDirectory(const char*, OsFile*); |
| 91 | int sqlite3OsTempFileName(char*); |
| 92 | int sqlite3OsClose(OsFile*); |
| 93 | int sqlite3OsRead(OsFile*, void*, int amt); |
| 94 | int sqlite3OsWrite(OsFile*, const void*, int amt); |
| 95 | int sqlite3OsSeek(OsFile*, off_t offset); |
| 96 | int sqlite3OsSync(OsFile*); |
| 97 | int sqlite3OsTruncate(OsFile*, off_t size); |
| 98 | int sqlite3OsFileSize(OsFile*, off_t *pSize); |
| 99 | int sqlite3OsReadLock(OsFile*); |
| 100 | int sqlite3OsWriteLock(OsFile*); |
| 101 | int sqlite3OsUnlock(OsFile*); |
| 102 | int sqlite3OsRandomSeed(char*); |
| 103 | int sqlite3OsSleep(int ms); |
| 104 | int sqlite3OsCurrentTime(double*); |
| 105 | void sqlite3OsEnterMutex(void); |
| 106 | void sqlite3OsLeaveMutex(void); |
| 107 | char *sqlite3OsFullPathname(const char*); |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 108 | |
drh | e3c4137 | 2001-09-17 20:25:58 +0000 | [diff] [blame] | 109 | #endif /* _SQLITE_OS_H_ */ |