engine/sqlite/src/os.cpp
author skip
Thu, 25 Feb 2010 14:29:19 +0000
changeset 2 29cda98b007e
permissions -rw-r--r--
Initial import of Podcatcher from the Bergamot project
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     1
 /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     2
** 2005 November 29
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     3
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     4
** The author disclaims copyright to this source code.  In place of
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     5
** a legal notice, here is a blessing:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     6
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     7
**    May you do good and not evil.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     8
**    May you find forgiveness for yourself and forgive others.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     9
**    May you share freely, never taking more than you give.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    10
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    11
******************************************************************************
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    12
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    13
** This file contains OS interface code that is common to all
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    14
** architectures.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    15
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    16
#define _SQLITE_OS_C_ 1
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    17
#include "sqliteInt.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    18
#undef _SQLITE_OS_C_
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    19
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    20
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    21
** The default SQLite sqlite3_vfs implementations do not allocate
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
** memory (actually, os_unix.c allocates a small amount of memory
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
** from within OsOpen()), but some third-party implementations may.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
** So we test the effects of a malloc() failing and the sqlite3OsXXX()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
** function returning SQLITE_IOERR_NOMEM using the DO_OS_MALLOC_TEST macro.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    26
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    27
** The following functions are instrumented for malloc() failure 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
** testing:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    29
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
**     sqlite3OsOpen()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
**     sqlite3OsRead()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
**     sqlite3OsWrite()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
**     sqlite3OsSync()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
**     sqlite3OsLock()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
#ifdef SQLITE_TEST
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
  #define DO_OS_MALLOC_TEST if (1) {            \
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
    void *pTstAlloc = sqlite3_malloc(10);       \
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
    if (!pTstAlloc) return SQLITE_IOERR_NOMEM;  \
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
    sqlite3_free(pTstAlloc);                    \
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
#else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
  #define DO_OS_MALLOC_TEST
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
** The following routines are convenience wrappers around methods
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
** of the sqlite3_file object.  This is mostly just syntactic sugar. All
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
** of this would be completely automatic if SQLite were coded using
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
** C++ instead of plain old C.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
int sqlite3OsClose(sqlite3_file *pId){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
  int rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
/*  if( pId->pMethods ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
    rc = pId->pMethods->xClose(pId);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
    pId->pMethods = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
  }*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
  rc = winClose(pId);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    60
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
int sqlite3OsRead(sqlite3_file *id, void *pBuf, int amt, i64 offset){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
  DO_OS_MALLOC_TEST;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
  //return id->pMethods->xRead(id, pBuf, amt, offset);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
  return winRead(id, pBuf, amt, offset);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
int sqlite3OsWrite(sqlite3_file *id, const void *pBuf, int amt, i64 offset){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
  DO_OS_MALLOC_TEST;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
  //return id->pMethods->xWrite(id, pBuf, amt, offset);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    70
  return winWrite(id, pBuf, amt, offset);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    71
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
int sqlite3OsTruncate(sqlite3_file *id, i64 size){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    73
  //return id->pMethods->xTruncate(id, size);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    74
	return winTruncate(id, size);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    75
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    76
int sqlite3OsSync(sqlite3_file *id, int flags){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
  DO_OS_MALLOC_TEST;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
//  return id->pMethods->xSync(id, flags);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
  return winSync(id, flags);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
int sqlite3OsFileSize(sqlite3_file *id, i64 *pSize){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
//  return id->pMethods->xFileSize(id, pSize);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
	return winFileSize(id, pSize);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    84
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
int sqlite3OsLock(sqlite3_file *id, int lockType){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
  DO_OS_MALLOC_TEST;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
  //return id->pMethods->xLock(id, lockType);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
  return winLock(id, lockType);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
int sqlite3OsUnlock(sqlite3_file *id, int lockType){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
  //return id->pMethods->xUnlock(id, lockType);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
	return winUnlock(id, lockType);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
int sqlite3OsCheckReservedLock(sqlite3_file *id){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
  //return id->pMethods->xCheckReservedLock(id);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
	return winCheckReservedLock(id);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
  //return id->pMethods->xFileControl(id,op,pArg);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
	return winFileControl(id, op, pArg);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
#ifdef SQLITE_TEST
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
  /* The following two variables are used to override the values returned
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
  ** by the xSectorSize() and xDeviceCharacteristics() vfs methods for
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
  ** testing purposes. They are usually set by a test command implemented
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
  ** in test6.c.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
  int sqlite3_test_sector_size = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
  int sqlite3_test_device_characteristics = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
  int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
    int dc = id->pMethods->xDeviceCharacteristics(id);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
    return dc | sqlite3_test_device_characteristics;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
  int sqlite3OsSectorSize(sqlite3_file *id){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
    if( sqlite3_test_sector_size==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
      int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
      return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
    return sqlite3_test_sector_size;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   122
#else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   123
  int sqlite3OsSectorSize(sqlite3_file *id){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
    //int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
    //return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   126
	  return winSectorSize(id);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
  int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
//    return id->pMethods->xDeviceCharacteristics(id);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
	  return winDeviceCharacteristics(id);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   133
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   134
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
** The next group of routines are convenience wrappers around the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
** VFS methods.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   137
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
int sqlite3OsOpen(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
  sqlite3_vfs *pVfs, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   140
  const char *zPath, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   141
  sqlite3_file *pFile, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
  int flags, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
  int *pFlagsOut
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   145
  //return pVfs->xOpen(pVfs, zPath, pFile, flags, pFlagsOut);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   146
  return winOpen(pVfs, zPath, pFile, flags, pFlagsOut);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   149
  //return pVfs->xDelete(pVfs, zPath, dirSync);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
	return winDelete(pVfs, zPath, dirSync);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   152
int sqlite3OsAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
//  return pVfs->xAccess(pVfs, zPath, flags);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
	return winAccess(pVfs, zPath, flags);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
int sqlite3OsGetTempname(sqlite3_vfs *pVfs, int nBufOut, char *zBufOut){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
//  return pVfs->xGetTempname(pVfs, nBufOut, zBufOut);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
	return winGetTempname(pVfs, nBufOut, zBufOut);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   159
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   160
int sqlite3OsFullPathname(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
  sqlite3_vfs *pVfs, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
  const char *zPath, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   163
  int nPathOut, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
  char *zPathOut
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   165
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   166
//  return pVfs->xFullPathname(pVfs, zPath, nPathOut, zPathOut);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
	return winFullPathname(pVfs, zPath, nPathOut, zPathOut);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
void *sqlite3OsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
//  return pVfs->xDlOpen(pVfs, zPath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   171
	return NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
void sqlite3OsDlError(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
//  pVfs->xDlError(pVfs, nByte, zBufOut);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
void *sqlite3OsDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
//  return pVfs->xDlSym(pVfs, pHandle, zSymbol);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
	return NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
void sqlite3OsDlClose(sqlite3_vfs *pVfs, void *pHandle){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
//  pVfs->xDlClose(pVfs, pHandle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
int sqlite3OsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
//  return pVfs->xRandomness(pVfs, nByte, zBufOut);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   186
	return winRandomness(pVfs, nByte, zBufOut);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   187
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   188
int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   189
//  return pVfs->xSleep(pVfs, nMicro);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
	return winSleep(pVfs, nMicro);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
int sqlite3OsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
//  return pVfs->xCurrentTime(pVfs, pTimeOut);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
	return winCurrentTime(pVfs, pTimeOut);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   195
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
int sqlite3OsOpenMalloc(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
  sqlite3_vfs *pVfs, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   199
  const char *zFile, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
  sqlite3_file **ppFile, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
  int flags,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   202
  int *pOutFlags
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   203
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   204
  int rc = SQLITE_NOMEM;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
  sqlite3_file *pFile;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
  pFile = (sqlite3_file *)sqlite3_malloc(pVfs->szOsFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   207
  if( pFile ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
    rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
    if( rc!=SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
      sqlite3_free(pFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   211
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   212
      *ppFile = pFile;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   217
int sqlite3OsCloseFree(sqlite3_file *pFile){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
  int rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
  if( pFile ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
    rc = sqlite3OsClose(pFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
    sqlite3_free(pFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   224
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
** The list of all registered VFS implementations.  This list is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
** initialized to the single VFS returned by sqlite3OsDefaultVfs()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
** upon the first call to sqlite3_vfs_find().
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
static sqlite3_vfs *vfsList = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
** Locate a VFS by name.  If no name is given, simply return the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
** first VFS on the list.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   236
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
EXPORT_C sqlite3_vfs *sqlite3_vfs_find(const char *zVfs){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
  sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
  sqlite3_vfs *pVfs = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
  static int isInit = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
  sqlite3_mutex_enter(mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
  if( !isInit ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
    vfsList = sqlite3OsDefaultVfs();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
    isInit = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
  for(pVfs = vfsList; pVfs; pVfs=pVfs->pNext){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
    if( zVfs==0 ) break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
    if( strcmp(zVfs, pVfs->zName)==0 ) break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
  sqlite3_mutex_leave(mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
  return pVfs;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   254
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
** Unlink a VFS from the linked list
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
static void vfsUnlink(sqlite3_vfs *pVfs){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   258
  assert( sqlite3_mutex_held(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER)) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
  if( pVfs==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
    /* No-op */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
  }else if( vfsList==pVfs ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
    vfsList = pVfs->pNext;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
  }else if( vfsList ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
    sqlite3_vfs *p = vfsList;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
    while( p->pNext && p->pNext!=pVfs ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
      p = p->pNext;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
    if( p->pNext==pVfs ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
      p->pNext = pVfs->pNext;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
** Register a VFS with the system.  It is harmless to register the same
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
** VFS multiple times.  The new VFS becomes the default if makeDflt is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
** true.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
EXPORT_C int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
  sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
  sqlite3_vfs_find(0);  /* Make sure we are initialized */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
  sqlite3_mutex_enter(mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
  vfsUnlink(pVfs);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   284
  if( makeDflt || vfsList==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   285
    pVfs->pNext = vfsList;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   286
    vfsList = pVfs;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   288
    pVfs->pNext = vfsList->pNext;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   289
    vfsList->pNext = pVfs;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   290
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
  assert(vfsList);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
  sqlite3_mutex_leave(mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
** Unregister a VFS so that it is no longer accessible.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   298
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   299
EXPORT_C int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
  sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
  sqlite3_mutex_enter(mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
  vfsUnlink(pVfs);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
  sqlite3_mutex_leave(mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
}