engine/sqlite/src/os_symbian.cpp
author Sebastian Brannstrom <sebastianb@symbian.org>
Sat, 23 Oct 2010 17:11:38 +0100
branch3rded
changeset 278 e6aa20533d01
parent 2 29cda98b007e
permissions -rw-r--r--
Merged fix for 3843
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
** 2008 February 09
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 code that is specific to windows.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    14
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    15
#include "sqliteInt.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    16
#if OS_SYMBIAN               /* This file is used for symbian only */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    17
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    18
#define MAX_PATH 260
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
** A Note About Memory Allocation:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    21
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
** This driver uses malloc()/free() directly rather than going through
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
** the SQLite-wrappers sqlite3_malloc()/sqlite3_free().  Those wrappers
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
** are designed for use on embedded systems where memory is scarce and
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
** malloc failures happen frequently.  Win32 does not typically run on
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    26
** embedded systems, and when it does the developers normally have bigger
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    27
** problems to worry about than running out of memory.  So there is not
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
** a compelling need to use the wrappers.
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
** But there is a good reason to not use the wrappers.  If we use the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
** wrappers then we will get simulated malloc() failures within this
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
** driver.  And that causes all kinds of problems for our tests.  We
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
** could enhance SQLite to deal with simulated malloc failures within
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
** the OS driver, but the code to deal with those failure would not
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
** be exercised on Linux (which does not need to malloc() in the driver)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
** and so we would have difficulty writing coverage tests for that
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
** code.  Better to leave the code out, we think.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
** The point of this discussion is as follows:  When creating a new
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
** OS layer for an embedded system, if you use this file as an example,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
** avoid the use of malloc()/free().  Those routines work ok on windows
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
** desktops but not so well in embedded systems.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
#include <stdlib.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
#include <string.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
#include <time.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
#include <e32std.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
#include <f32file.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
#include <charconv.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
#include <bautils.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
#include <unistd.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
** Macros used to determine whether or not to use threads.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
#if defined(THREADSAFE) && THREADSAFE
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
# define SQLITE_W32_THREADS 1
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    60
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
** Include code that is common to all os_*.c files
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
#include "os_common.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
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
** The symbianFile structure is a subclass of sqlite3_file* specific to the win32
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
** portability layer.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    70
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    71
typedef struct symbianFile symbianFile;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
struct symbianFile {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    73
	int isOpen;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    74
  unsigned char locktype; /* Type of lock currently held on this file */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    75
  short sharedLockByte;   /* Randomly chosen byte used as a shared lock */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    76
  char fileName[512];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
  RFs session;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
  RFile file;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
};
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
/*****************************************************************************
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
** The next group of routines implement the I/O methods specified
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
** by the sqlite3_io_methods object.
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
** Close a file.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
** It is reported that an attempt to close a handle might sometimes
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
** fail.  This is a very unreasonable result, but windows is notorious
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
** for being unreasonable so I do not doubt that it might happen.  If
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
** the close fails, we pause for 100 milliseconds and try again.  As
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
** many as MX_CLOSE_ATTEMPT attempts to close the handle are made before
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
** giving up and returning an error.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
#define MX_CLOSE_ATTEMPT 3
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
int winClose(sqlite3_file *id){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
  int rc, cnt = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
  symbianFile *pFile = (symbianFile*)id;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
  pFile->file.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
  pFile->session.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
** Some microsoft compilers lack this definition.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
#ifndef INVALID_SET_FILE_POINTER
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
# define INVALID_SET_FILE_POINTER ((DWORD)-1)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
** Read data from a file into a buffer.  Return SQLITE_OK if all
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
** bytes were read successfully and SQLITE_IOERR if anything goes
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
** wrong.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
int winRead(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
  sqlite3_file *id,          /* File to read from */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
  void *pBuf,                /* Write content into this buffer */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
  int amt,                   /* Number of bytes to read */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
  sqlite3_int64 offset       /* Begin reading at this offset */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   122
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   123
  int rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
  size_t got;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
  symbianFile *pFile = (symbianFile*)id;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   126
  assert( id!=0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
  SimulateIOError(return SQLITE_IOERR_READ);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
  TInt tOffset = (TInt)offset;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
  rc = pFile->file.Seek(ESeekStart, tOffset);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
  if( rc!= KErrNone){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
    return SQLITE_FULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
  }
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
  HBufC8* buf = HBufC8::NewL(amt) ;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
  TPtr8 ptr = buf->Des();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   137
  if (pFile->file.Read(ptr, amt) != KErrNone)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
	  {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
	    delete buf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   140
	    return SQLITE_IOERR_READ;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   141
	  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
  got = buf->Length();
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
  if( got == 0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   146
	  delete buf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
	  TInt size = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
	  if (pFile->file.Size(size) != KErrNone) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   149
	  {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
		  return SQLITE_IOERR_READ;
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
	  if (size == 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
	  {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
		  return SQLITE_IOERR_SHORT_READ;
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
    return SQLITE_IOERR_READ;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
 }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
  memcpy(pBuf, ptr.Ptr(), got);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   159
  delete buf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   160
 if( got == amt ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
    return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   163
    memset(&((char*)pBuf)[got], 0, amt-got);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
    return SQLITE_IOERR_SHORT_READ;
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
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
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
** Write data from a buffer into a file.  Return SQLITE_OK on success
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
** or some other error code on failure.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   171
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
int winWrite(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
  sqlite3_file *id,         /* File to write into */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
  const void *pBuf,         /* The bytes to be written */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
  int amt,                  /* Number of bytes to write */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
  sqlite3_int64 offset      /* Offset into the file to begin writing at */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
  int rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
  symbianFile *pFile = (symbianFile*)id;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
  assert( id!=0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
  SimulateIOError(return SQLITE_IOERR_WRITE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
  SimulateDiskfullError(return SQLITE_FULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
  TInt tOffset = (TInt)offset;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
  rc = pFile->file.Seek(ESeekStart, tOffset);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
  if( rc!= KErrNone){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   186
    return SQLITE_FULL;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   189
  assert( amt>0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
  rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
  TPtrC8 ptr((TUint8 *)pBuf,amt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
  if (pFile->file.Write(ptr, amt) != KErrNone) rc = SQLITE_FULL;
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
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   199
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
** Truncate an open file to a specified size
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   202
int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   203
  symbianFile *pFile = (symbianFile*)id;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   204
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
  if (pFile->file.SetSize(nByte) != KErrNone)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
  {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   207
	  return SQLITE_IOERR; 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   211
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   212
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
#ifdef SQLITE_TEST
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
** Count the number of fullsyncs and normal syncs.  This is used to test
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
** that syncs and fullsyncs are occuring at the right times.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   217
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
int sqlite3_sync_count = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
int sqlite3_fullsync_count = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
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
** Make sure all writes to a particular file are committed to disk.
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
int winSync(sqlite3_file *id, int flags){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
  symbianFile *pFile = (symbianFile*)id;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
  OSTRACE3("SYNC %d lock=%d\n", pFile->h, pFile->locktype);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
#ifdef SQLITE_TEST
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
  if( flags & SQLITE_SYNC_FULL ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
    sqlite3_fullsync_count++;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
  sqlite3_sync_count++;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
  TInt error = pFile->file.Flush();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
  if (error != KErrNone)
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
    return SQLITE_IOERR;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
    return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
** Determine the current size of a file in bytes
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
int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
  symbianFile *pFile = (symbianFile*)id;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
  TInt size = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
  if (pFile->file.Size(size) != KErrNone)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
  {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
	  return SQLITE_IOERR;
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
  *pSize = size;
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
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   258
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
** Lock the file with the lock specified by parameter locktype - one
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
** of the following:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
**     (1) SHARED_LOCK
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
**     (2) RESERVED_LOCK
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
**     (3) PENDING_LOCK
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
**     (4) EXCLUSIVE_LOCK
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
** Sometimes when requesting one lock state, additional lock states
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
** are inserted in between.  The locking might fail on one of the later
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
** transitions leaving the lock state different from what it started but
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
** still short of its goal.  The following chart shows the allowed
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
** transitions and the inserted intermediate states:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
**    UNLOCKED -> SHARED
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
**    SHARED -> RESERVED
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
**    SHARED -> (PENDING) -> EXCLUSIVE
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
**    RESERVED -> (PENDING) -> EXCLUSIVE
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
**    PENDING -> EXCLUSIVE
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
** This routine will only increase a lock.  The winUnlock() routine
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
** erases all locks at once and returns us immediately to locking level 0.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   284
** It is not possible to lower the locking level one step at a time.  You
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   285
** must go straight to locking level 0.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   286
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
int winLock(sqlite3_file *id, int locktype){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   288
  int rc = SQLITE_OK;    /* Return code from subroutines */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   289
  int res = 1;           /* Result of a windows lock call */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   290
  int newLocktype;       /* Set pFile->locktype to this value before exiting */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
  int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
  symbianFile *pFile = (symbianFile*)id;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
  assert( pFile!=0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
  OSTRACE5("LOCK %d %d was %d(%d)\n",
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
          pFile->h, locktype, pFile->locktype, pFile->sharedLockByte);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   298
  // one smartphone only one application can control the database
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   299
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
  TInt size = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
  if (pFile->file.Size(size) == KErrNone) return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
  return SQLITE_BUSY;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   306
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   307
** This routine checks if there is a RESERVED lock held on the specified
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
** file by this or any other process. If such a lock is held, return
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   309
** non-zero, otherwise zero.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   310
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   311
int winCheckReservedLock(sqlite3_file *id){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   312
  int rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   313
  symbianFile *pFile = (symbianFile*)id;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   314
  assert( pFile!=0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   315
  if( pFile->locktype>=RESERVED_LOCK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   316
    rc = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
    OSTRACE3("TEST WR-LOCK %d %d (local)\n", pFile->h, rc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   318
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   319
	  TInt size = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   320
	  if (pFile->file.Size(size) == KErrNone) rc = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   321
    OSTRACE3("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   322
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   323
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   326
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   327
** Lower the locking level on file descriptor id to locktype.  locktype
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   328
** must be either NO_LOCK or SHARED_LOCK.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   329
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   330
** If the locking level of the file descriptor is already at or below
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   331
** the requested locking level, this routine is a no-op.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   332
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   333
** It is not possible for this routine to fail if the second argument
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   334
** is NO_LOCK.  If the second argument is SHARED_LOCK then this routine
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   335
** might return SQLITE_IOERR;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   336
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   337
int winUnlock(sqlite3_file *id, int locktype){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   338
  int type;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   339
  symbianFile *pFile = (symbianFile*)id;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   340
  int rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   341
  assert( pFile!=0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   342
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   343
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   344
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   345
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   346
** Control and query of the open file handle.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   347
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   348
int winFileControl(sqlite3_file *id, int op, void *pArg){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   349
  switch( op ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   350
    case SQLITE_FCNTL_LOCKSTATE: {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   351
      *(int*)pArg = ((symbianFile*)id)->locktype;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   352
      return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   353
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   354
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   355
  return SQLITE_ERROR;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   356
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   357
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   358
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   359
** Return the sector size in bytes of the underlying block device for
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   360
** the specified file. This is almost always 512 bytes, but may be
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   361
** larger for some devices.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   362
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   363
** SQLite code assumes this function cannot fail. It also assumes that
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   364
** if two files are created in the same file-system directory (i.e.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   365
** a database and its journal file) that the sector size will be the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   366
** same for both.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   367
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   368
int winSectorSize(sqlite3_file *id){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   369
  return SQLITE_DEFAULT_SECTOR_SIZE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   370
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   371
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   372
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   373
** Return a vector of device characteristics.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   374
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   375
int winDeviceCharacteristics(sqlite3_file *id){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   376
  return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   377
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   378
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   379
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   380
/***************************************************************************
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   381
** Here ends the I/O methods that form the sqlite3_io_methods object.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   382
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   383
** The next block of code implements the VFS methods.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   384
****************************************************************************/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   385
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   386
void ConvertToUnicode(RFs session, TDes16& aUnicode, const char *str)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   387
{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   388
  CCnvCharacterSetConverter *converter = CCnvCharacterSetConverter::NewL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   389
  converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierUtf8, session);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   390
  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   391
  TPtrC8 ptr((const unsigned char*)str);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   392
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   393
  int state = CCnvCharacterSetConverter::KStateDefault;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   394
  converter->ConvertToUnicode(aUnicode, ptr, state);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   395
  delete converter;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   396
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   397
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   398
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   399
** Open a file.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   400
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   401
int winOpen(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   402
  sqlite3_vfs *pVfs,        /* Not used */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   403
  const char *zName,        /* Name of the file (UTF-8) */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   404
  sqlite3_file *id,         /* Write the SQLite file handle here */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   405
  int flags,                /* Open mode flags */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   406
  int *pOutFlags            /* Status return flags */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   407
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   408
  symbianFile *pFile = (symbianFile*)id;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   409
  TBuf16<MAX_PATH> filename;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   410
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   411
  pFile->isOpen = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   412
  memset(pFile, 0, sizeof(*pFile));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   413
  strcpy(pFile->fileName, zName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   414
  pFile->session.Connect();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   415
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   416
  ConvertToUnicode(pFile->session, filename, zName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   417
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   418
  int ret = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   419
  if( flags & SQLITE_OPEN_CREATE ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   420
    if (BaflUtils::FileExists(pFile->session, filename) == 1)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   421
    	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   422
  	  ret = pFile->file.Open(pFile->session, filename, EFileStream | EFileWrite);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   423
    	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   424
    else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   425
    	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   426
    	ret = pFile->file.Create(pFile->session, filename, EFileStream | EFileWrite);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   427
    	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   428
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   429
  else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   430
  if( flags & SQLITE_OPEN_READWRITE ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   431
	  ret = pFile->file.Open(pFile->session, filename, EFileStream | EFileWrite);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   432
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   433
	ret = pFile->file.Open(pFile->session, filename, EFileStream | EFileRead);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   434
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   435
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   436
  OpenCounter(+1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   437
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   438
  if (ret != KErrNone)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   439
  {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   440
	  return SQLITE_IOERR;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   441
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   442
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   443
  pFile->isOpen = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   444
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   445
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   446
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   447
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   448
** Delete the named file.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   449
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   450
** Note that windows does not allow a file to be deleted if some other
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   451
** process has it open.  Sometimes a virus scanner or indexing program
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   452
** will open a journal file shortly after it is created in order to do
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   453
** whatever does.  While this other process is holding the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   454
** file open, we will be unable to delete it.  To work around this
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   455
** problem, we delay 100 milliseconds and try to delete again.  Up
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   456
** to MX_DELETION_ATTEMPTs deletion attempts are run before giving
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   457
** up and returning an error.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   458
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   459
#define MX_DELETION_ATTEMPTS 5
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   460
int winDelete(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   461
  sqlite3_vfs *pVfs,          /* Not used on win32 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   462
  const char *zFilename,      /* Name of file to delete */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   463
  int syncDir                 /* Not used on win32 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   464
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   465
  SimulateIOError(return SQLITE_IOERR_DELETE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   466
  TBuf16<MAX_PATH> filename;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   467
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   468
  RFs session;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   469
  session.Connect();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   470
  ConvertToUnicode(session, filename, zFilename);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   471
  BaflUtils::DeleteFile(session, filename);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   472
  OSTRACE2("DELETE \"%s\"\n", zFilename);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   473
  session.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   474
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   475
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   476
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   477
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   478
** Check the existance and status of a file.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   479
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   480
int winAccess(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   481
  sqlite3_vfs *pVfs,         /* Not used on win32 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   482
  const char *zFilename,     /* Name of file to check */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   483
  int flags                  /* Type of test to make on this file */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   484
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   485
  TBuf16<MAX_PATH> filename;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   486
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   487
  RFs session;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   488
  session.Connect();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   489
  ConvertToUnicode(session, filename, zFilename);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   490
  int ret = BaflUtils::FileExists(session, filename);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   491
  session.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   492
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   493
  return ret;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   494
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   495
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   496
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   497
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   498
** Create a temporary file name in zBuf.  zBuf must be big enough to
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   499
** hold at pVfs->mxPathname characters.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   500
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   501
int winGetTempname(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   502
  static char zChars[] =
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   503
    "abcdefghijklmnopqrstuvwxyz"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   504
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   505
    "0123456789";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   506
  int i, j;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   507
  char zTempPath[MAX_PATH+1];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   508
  if( sqlite3_temp_directory ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   509
    sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   510
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   511
  else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   512
  {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   513
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   514
  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   515
  for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   516
  zTempPath[i] = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   517
  sqlite3_snprintf(nBuf-30, zBuf,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   518
                   "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   519
  j = strlen(zBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   520
  sqlite3Randomness(20, &zBuf[j]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   521
  for(i=0; i<20; i++, j++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   522
    zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   523
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   524
  zBuf[j] = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   525
  OSTRACE2("TEMP FILENAME: %s\n", zBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   526
  return SQLITE_OK; 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   527
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   528
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   529
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   530
** Turn a relative pathname into a full pathname.  Write the full
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   531
** pathname into zOut[].  zOut[] will be at least pVfs->mxPathname
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   532
** bytes in size.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   533
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   534
int winFullPathname(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   535
  sqlite3_vfs *pVfs,            /* Pointer to vfs object */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   536
  const char *zRelative,        /* Possibly relative input path */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   537
  int nFull,                    /* Size of output buffer in bytes */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   538
  char *zFull                   /* Output buffer */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   539
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   540
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   541
  /* WinCE has no concept of a relative pathname, or so I am told. */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   542
  sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zRelative);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   543
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   544
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   545
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   546
  #define winDlOpen  0
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   547
  #define winDlError 0
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   548
  #define winDlSym   0
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   549
  #define winDlClose 0
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   550
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   551
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   552
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   553
** Write up to nBuf bytes of randomness into zBuf.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   554
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   555
int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   556
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   557
	int i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   558
	for (i=0; i<nBuf; ++i)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   559
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   560
		zBuf[i] = rand() % 255;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   561
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   562
	return nBuf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   563
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   564
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   565
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   566
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   567
** Sleep for a little while.  Return the amount of time slept.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   568
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   569
int winSleep(sqlite3_vfs *pVfs, int microsec){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   570
	return sleep(microsec / 1000);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   571
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   572
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   573
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   574
** The following variable, if set to a non-zero value, becomes the result
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   575
** returned from sqlite3OsCurrentTime().  This is used for testing.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   576
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   577
#ifdef SQLITE_TEST
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   578
int sqlite3_current_time = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   579
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   580
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   581
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   582
** Find the current time (in Universal Coordinated Time).  Write the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   583
** current time and date as a Julian Day number into *prNow and
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   584
** return 0.  Return 1 if the time and date cannot be found.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   585
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   586
int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   587
  double now;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   588
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   589
  now = time(NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   590
  *prNow = now;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   591
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   592
  return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   593
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   594
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   595
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   596
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   597
** Return a pointer to the sqlite3DefaultVfs structure.   We use
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   598
** a function rather than give the structure global scope because
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   599
** some compilers (MSVC) do not allow forward declarations of
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   600
** initialized structures.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   601
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   602
sqlite3_vfs *sqlite3OsDefaultVfs(void){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   603
  static sqlite3_vfs winVfs = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   604
    1,                 /* iVersion */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   605
    -1,   /* szOsFile */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   606
    MAX_PATH,          /* mxPathname */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   607
    0,                 /* pNext */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   608
    "symbian",           /* zName */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   609
    0,                 /* pAppData */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   610
    };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   611
  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   612
  winVfs.szOsFile = sizeof(symbianFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   613
  return &winVfs;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   614
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   615
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   616
#endif /* OS_SYMBIAN */