Back to index

php5  5.3.10
os.h
Go to the documentation of this file.
00001 /*
00002 ** 2001 September 16
00003 **
00004 ** The author disclaims copyright to this source code.  In place of
00005 ** a legal notice, here is a blessing:
00006 **
00007 **    May you do good and not evil.
00008 **    May you find forgiveness for yourself and forgive others.
00009 **    May you share freely, never taking more than you give.
00010 **
00011 ******************************************************************************
00012 **
00013 ** This header file (together with is companion C source-code file
00014 ** "os.c") attempt to abstract the underlying operating system so that
00015 ** the SQLite library will work on both POSIX and windows systems.
00016 */
00017 #ifndef _SQLITE_OS_H_
00018 #define _SQLITE_OS_H_
00019 
00020 /*
00021 ** Helpful hint:  To get this to compile on HP/UX, add -D_INCLUDE_POSIX_SOURCE
00022 ** to the compiler command line.
00023 */
00024 
00025 /*
00026 ** These #defines should enable >2GB file support on Posix if the
00027 ** underlying operating system supports it.  If the OS lacks
00028 ** large file support, or if the OS is windows, these should be no-ops.
00029 **
00030 ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
00031 ** on the compiler command line.  This is necessary if you are compiling
00032 ** on a recent machine (ex: RedHat 7.2) but you want your code to work
00033 ** on an older machine (ex: RedHat 6.0).  If you compile on RedHat 7.2
00034 ** without this option, LFS is enable.  But LFS does not exist in the kernel
00035 ** in RedHat 6.0, so the code won't work.  Hence, for maximum binary
00036 ** portability you should omit LFS.
00037 **
00038 ** Similar is true for MacOS.  LFS is only supported on MacOS 9 and later.
00039 */
00040 #ifndef SQLITE_DISABLE_LFS
00041 # define _LARGE_FILE       1
00042 # ifndef _FILE_OFFSET_BITS
00043 #   define _FILE_OFFSET_BITS 64
00044 # endif
00045 # define _LARGEFILE_SOURCE 1
00046 #endif
00047 
00048 /*
00049 ** Temporary files are named starting with this prefix followed by 16 random
00050 ** alphanumeric characters, and no file extension. They are stored in the
00051 ** OS's standard temporary file directory, and are deleted prior to exit.
00052 ** If sqlite is being embedded in another program, you may wish to change the
00053 ** prefix to reflect your program's name, so that if your program exits
00054 ** prematurely, old temporary files can be easily identified. This can be done
00055 ** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line.
00056 */
00057 #ifndef TEMP_FILE_PREFIX
00058 # define TEMP_FILE_PREFIX "sqlite_"
00059 #endif
00060 
00061 /*
00062 ** Figure out if we are dealing with Unix, Windows or MacOS.
00063 **
00064 ** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
00065 **      The MacOS build is designed to use CodeWarrior (tested with v8)
00066 */
00067 #ifndef OS_UNIX
00068 # ifndef OS_WIN
00069 #  ifndef OS_MAC
00070 #    if defined(__MACOS__)
00071 #      define OS_MAC 1
00072 #      define OS_WIN 0
00073 #      define OS_UNIX 0
00074 #    elif defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
00075 #      define OS_MAC 0
00076 #      define OS_WIN 1
00077 #      define OS_UNIX 0
00078 #    else
00079 #      define OS_MAC 0
00080 #      define OS_WIN 0
00081 #      define OS_UNIX 1
00082 #    endif
00083 #  else
00084 #    define OS_WIN 0
00085 #    define OS_UNIX 0
00086 #  endif
00087 # else
00088 #  define OS_MAC 0
00089 #  define OS_UNIX 0
00090 # endif
00091 #else
00092 # define OS_MAC 0
00093 # ifndef OS_WIN
00094 #  define OS_WIN 0
00095 # endif
00096 #endif
00097 
00098 /*
00099 ** A handle for an open file is stored in an OsFile object.
00100 */
00101 #if OS_UNIX
00102 # include <sys/types.h>
00103 # include <sys/stat.h>
00104 # include <fcntl.h>
00105 # include <unistd.h>
00106   typedef struct OsFile OsFile;
00107   struct OsFile {
00108     struct openCnt *pOpen;    /* Info about all open fd's on this inode */
00109     struct lockInfo *pLock;   /* Info about locks on this inode */
00110     int fd;                   /* The file descriptor */
00111     int locked;               /* True if this instance holds the lock */
00112     int dirfd;                /* File descriptor for the directory */
00113   };
00114 # define SQLITE_TEMPNAME_SIZE 200
00115 # if defined(HAVE_USLEEP) && HAVE_USLEEP
00116 #  define SQLITE_MIN_SLEEP_MS 1
00117 # else
00118 #  define SQLITE_MIN_SLEEP_MS 1000
00119 # endif
00120 #endif
00121 
00122 #if OS_WIN
00123 #include <windows.h>
00124 #include <winbase.h>
00125   typedef struct OsFile OsFile;
00126   struct OsFile {
00127     HANDLE h;               /* Handle for accessing the file */
00128     int locked;             /* 0: unlocked, <0: write lock, >0: read lock */
00129   };
00130 # if defined(_MSC_VER) || defined(__BORLANDC__)
00131     typedef __int64 off_t;
00132 # else
00133 #  if !defined(_CYGWIN_TYPES_H)
00134      typedef long long off_t;
00135 #    if defined(__MINGW32__)
00136 #      define _OFF_T_
00137 #    endif
00138 #  endif
00139 # endif
00140 # define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
00141 # define SQLITE_MIN_SLEEP_MS 1
00142 #endif
00143 
00144 #if OS_MAC
00145 # include <unistd.h>
00146 # include <Files.h>
00147   typedef struct OsFile OsFile;
00148   struct OsFile {
00149     SInt16 refNum;           /* Data fork/file reference number */
00150     SInt16 refNumRF;         /* Resource fork reference number (for locking) */
00151     int locked;              /* 0: unlocked, <0: write lock, >0: read lock */
00152     int delOnClose;          /* True if file is to be deleted on close */
00153     char *pathToDel;         /* Name of file to delete on close */
00154   };
00155 # ifdef _LARGE_FILE
00156     typedef SInt64 off_t;
00157 # else
00158     typedef SInt32 off_t;
00159 # endif
00160 # define SQLITE_TEMPNAME_SIZE _MAX_PATH
00161 # define SQLITE_MIN_SLEEP_MS 17
00162 #endif
00163 
00164 int sqliteOsDelete(const char*);
00165 int sqliteOsFileExists(const char*);
00166 int sqliteOsFileRename(const char*, const char*);
00167 int sqliteOsOpenReadWrite(const char*, OsFile*, int*);
00168 int sqliteOsOpenExclusive(const char*, OsFile*, int);
00169 int sqliteOsOpenReadOnly(const char*, OsFile*);
00170 int sqliteOsOpenDirectory(const char*, OsFile*);
00171 int sqliteOsTempFileName(char*);
00172 int sqliteOsClose(OsFile*);
00173 int sqliteOsRead(OsFile*, void*, int amt);
00174 int sqliteOsWrite(OsFile*, const void*, int amt);
00175 int sqliteOsSeek(OsFile*, off_t offset);
00176 int sqliteOsSync(OsFile*);
00177 int sqliteOsTruncate(OsFile*, off_t size);
00178 int sqliteOsFileSize(OsFile*, off_t *pSize);
00179 int sqliteOsReadLock(OsFile*);
00180 int sqliteOsWriteLock(OsFile*);
00181 int sqliteOsUnlock(OsFile*);
00182 int sqliteOsRandomSeed(char*);
00183 int sqliteOsSleep(int ms);
00184 int sqliteOsCurrentTime(double*);
00185 void sqliteOsEnterMutex(void);
00186 void sqliteOsLeaveMutex(void);
00187 char *sqliteOsFullPathname(const char*);
00188 
00189 
00190 
00191 #endif /* _SQLITE_OS_H_ */