/ Check-in [ed88fb00]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Work in progress to implement the 'syscall' functionality for Windows.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | winSyscall
Files: files | file ages | folders
SHA1: ed88fb00240de75457c0da19e87c12082622ca17
User & Date: mistachkin 2011-11-11 22:08:54
Context
2011-11-11
23:31
Remove use of malloc and free from the Windows VFS. Also, prevent sqlite3BtreeOpen from assuming that sqlite3OsFullPathname cannot fail. check-in: 8966ec17 user: mistachkin tags: winSyscall
22:08
Work in progress to implement the 'syscall' functionality for Windows. check-in: ed88fb00 user: mistachkin tags: winSyscall
2011-11-10
21:45
Expand passing of a last error argument to the getLastErrorMsg function. Also, remove unused SQLITE_W32_THREADS define. check-in: 8f287979 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   ******************************************************************************
    12     12   **
    13         -** This file contains code that is specific to windows.
           13  +** This file contains code that is specific to Windows.
    14     14   */
    15     15   #include "sqliteInt.h"
    16         -#if SQLITE_OS_WIN               /* This file is used for windows only */
           16  +#if SQLITE_OS_WIN               /* This file is used for Windows only */
    17     17   
    18     18   
    19     19   /*
    20     20   ** A Note About Memory Allocation:
    21     21   **
    22     22   ** This driver uses malloc()/free() directly rather than going through
    23     23   ** the SQLite-wrappers sqlite3_malloc()/sqlite3_free().  Those wrappers
................................................................................
    34     34   ** the OS driver, but the code to deal with those failure would not
    35     35   ** be exercised on Linux (which does not need to malloc() in the driver)
    36     36   ** and so we would have difficulty writing coverage tests for that
    37     37   ** code.  Better to leave the code out, we think.
    38     38   **
    39     39   ** The point of this discussion is as follows:  When creating a new
    40     40   ** OS layer for an embedded system, if you use this file as an example,
    41         -** avoid the use of malloc()/free().  Those routines work ok on windows
           41  +** avoid the use of malloc()/free().  Those routines work ok on Windows
    42     42   ** desktops but not so well in embedded systems.
    43     43   */
    44     44   
    45         -#include <winbase.h>
    46         -
    47     45   #ifdef __CYGWIN__
    48     46   # include <sys/cygwin.h>
    49     47   #endif
    50     48   
    51     49   /*
    52     50   ** Include code that is common to all os_*.c files
    53     51   */
    54     52   #include "os_common.h"
    55     53   
    56     54   /*
    57         -** Some microsoft compilers lack this definition.
           55  +** Some Microsoft compilers lack this definition.
    58     56   */
    59     57   #ifndef INVALID_FILE_ATTRIBUTES
    60     58   # define INVALID_FILE_ATTRIBUTES ((DWORD)-1) 
    61     59   #endif
    62     60   
    63         -/*
    64         -** Determine if we are dealing with WindowsCE - which has a much
    65         -** reduced API.
    66         -*/
    67         -#if SQLITE_OS_WINCE
    68         -# define AreFileApisANSI() 1
    69         -# define FormatMessageW(a,b,c,d,e,f,g) 0
    70         -#endif
    71         -
    72     61   /* Forward references */
    73     62   typedef struct winShm winShm;           /* A connection to shared-memory */
    74     63   typedef struct winShmNode winShmNode;   /* A region of shared-memory */
    75     64   
    76     65   /*
    77     66   ** WinCE lacks native support for file locking so we have to fake it
    78     67   ** with some code of our own.
................................................................................
   100     89     u8 bPersistWal;         /* True to persist WAL files */
   101     90     DWORD lastErrno;        /* The Windows errno from the last I/O error */
   102     91     DWORD sectorSize;       /* Sector size of the device file is on */
   103     92     winShm *pShm;           /* Instance of shared memory on this file */
   104     93     const char *zPath;      /* Full pathname of this file */
   105     94     int szChunk;            /* Chunk size configured by FCNTL_CHUNK_SIZE */
   106     95   #if SQLITE_OS_WINCE
   107         -  WCHAR *zDeleteOnClose;  /* Name of file to delete when closing */
           96  +  LPWSTR zDeleteOnClose;  /* Name of file to delete when closing */
   108     97     HANDLE hMutex;          /* Mutex used to control access to shared lock */  
   109     98     HANDLE hShared;         /* Shared memory segment used for locking */
   110     99     winceLock local;        /* Locks obtained by this instance of winFile */
   111    100     winceLock *shared;      /* Global shared lock memory for the file  */
   112    101   #endif
   113    102   };
   114    103   
................................................................................
   204    193   ** can manually set this value to 1 to emulate Win98 behavior.
   205    194   */
   206    195   #ifdef SQLITE_TEST
   207    196   int sqlite3_os_type = 0;
   208    197   #else
   209    198   static int sqlite3_os_type = 0;
   210    199   #endif
          200  +
          201  +/*
          202  +** Many system calls are accessed through pointer-to-functions so that
          203  +** they may be overridden at runtime to facilitate fault injection during
          204  +** testing and sandboxing.  The following array holds the names and pointers
          205  +** to all overrideable system calls.
          206  +*/
          207  +#if !SQLITE_OS_WINCE
          208  +#  define SQLITE_WIN32_HAS_ANSI
          209  +#endif
          210  +
          211  +#if SQLITE_OS_WINCE || defined(_WIN32_WINNT)
          212  +#  define SQLITE_WIN32_HAS_WIDE
          213  +#endif
          214  +
          215  +#ifndef SYSCALL
          216  +#  define SYSCALL sqlite3_syscall_ptr
          217  +#endif
          218  +
          219  +#if SQLITE_OS_WINCE
          220  +/*
          221  +** These macros are necessary because Windows CE does not natively support the
          222  +** Win32 APIs LockFile, UnlockFile, and LockFileEx.
          223  + */
          224  +
          225  +#  define LockFile(a,b,c,d,e)       winceLockFile(&a, b, c, d, e)
          226  +#  define UnlockFile(a,b,c,d,e)     winceUnlockFile(&a, b, c, d, e)
          227  +#  define LockFileEx(a,b,c,d,e,f)   winceLockFileEx(&a, b, c, d, e, f)
          228  +
          229  +/*
          230  +** These are the special syscall hacks for Windows CE.  The locking related
          231  +** defines here refer to the macros defined just above.
          232  + */
          233  +
          234  +#  define osAreFileApisANSI()       1
          235  +#  define osLockFile                LockFile
          236  +#  define osUnlockFile              UnlockFile
          237  +#  define osLockFileEx              LockFileEx
          238  +#endif
          239  +
          240  +static struct win_syscall {
          241  +  const char *zName;            /* Name of the sytem call */
          242  +  sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
          243  +  sqlite3_syscall_ptr pDefault; /* Default value */
          244  +} aSyscall[] = {
          245  +#if !SQLITE_OS_WINCE
          246  +  { "AreFileApisANSI",         (SYSCALL)AreFileApisANSI,         0 },
          247  +
          248  +#define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent)
          249  +#else
          250  +  { "AreFileApisANSI",         (SYSCALL)0,                       0 },
          251  +#endif
          252  +
          253  +#if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
          254  +  { "CharLowerW",              (SYSCALL)CharLowerW,              0 },
          255  +#else
          256  +  { "CharLowerW",              (SYSCALL)0,                       0 },
          257  +#endif
          258  +
          259  +#define osCharLowerW ((LPWSTR(WINAPI*)(LPWSTR))aSyscall[1].pCurrent)
          260  +
          261  +#if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
          262  +  { "CharUpperW",              (SYSCALL)CharUpperW,              0 },
          263  +#else
          264  +  { "CharUpperW",              (SYSCALL)0,                       0 },
          265  +#endif
          266  +
          267  +#define osCharUpperW ((LPWSTR(WINAPI*)(LPWSTR))aSyscall[2].pCurrent)
          268  +
          269  +  { "CloseHandle",             (SYSCALL)CloseHandle,             0 },
          270  +
          271  +#define osCloseHandle ((BOOL(WINAPI*)(HANDLE))aSyscall[3].pCurrent)
          272  +
          273  +#if defined(SQLITE_WIN32_HAS_ANSI)
          274  +  { "CreateFileA",             (SYSCALL)CreateFileA,             0 },
          275  +#else
          276  +  { "CreateFileA",             (SYSCALL)0,                       0 },
          277  +#endif
          278  +
          279  +#define osCreateFileA ((HANDLE(WINAPI*)(LPCSTR,DWORD,DWORD, \
          280  +        LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[4].pCurrent)
          281  +
          282  +#if defined(SQLITE_WIN32_HAS_WIDE)
          283  +  { "CreateFileW",             (SYSCALL)CreateFileW,             0 },
          284  +#else
          285  +  { "CreateFileW",             (SYSCALL)0,                       0 },
          286  +#endif
          287  +
          288  +#define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
          289  +        LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
          290  +
          291  +  { "CreateFileMapping",       (SYSCALL)CreateFileMapping,       0 },
          292  +
          293  +#define osCreateFileMapping ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
          294  +        DWORD,DWORD,DWORD,LPCTSTR))aSyscall[6].pCurrent)
          295  +
          296  +#if defined(SQLITE_WIN32_HAS_WIDE)
          297  +  { "CreateFileMappingW",      (SYSCALL)CreateFileMappingW,      0 },
          298  +#else
          299  +  { "CreateFileMappingW",      (SYSCALL)0,                       0 },
          300  +#endif
          301  +
          302  +#define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
          303  +        DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent)
          304  +
          305  +#if defined(SQLITE_WIN32_HAS_WIDE)
          306  +  { "CreateMutexW",            (SYSCALL)CreateMutexW,            0 },
          307  +#else
          308  +  { "CreateMutexW",            (SYSCALL)0,                       0 },
          309  +#endif
          310  +
          311  +#define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \
          312  +        LPCWSTR))aSyscall[8].pCurrent)
          313  +
          314  +#if defined(SQLITE_WIN32_HAS_ANSI)
          315  +  { "DeleteFileA",             (SYSCALL)DeleteFileA,             0 },
          316  +#else
          317  +  { "DeleteFileA",             (SYSCALL)0,                       0 },
          318  +#endif
          319  +
          320  +#define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[9].pCurrent)
          321  +
          322  +#if defined(SQLITE_WIN32_HAS_WIDE)
          323  +  { "DeleteFileW",             (SYSCALL)DeleteFileW,             0 },
          324  +#else
          325  +  { "DeleteFileW",             (SYSCALL)0,                       0 },
          326  +#endif
          327  +
          328  +#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent)
          329  +
          330  +#if SQLITE_OS_WINCE
          331  +  { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
          332  +#else
          333  +  { "FileTimeToLocalFileTime", (SYSCALL)0,                       0 },
          334  +#endif
          335  +
          336  +#define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \
          337  +        LPFILETIME))aSyscall[11].pCurrent)
          338  +
          339  +#if SQLITE_OS_WINCE
          340  +  { "FileTimeToSystemTime",    (SYSCALL)FileTimeToSystemTime,    0 },
          341  +#else
          342  +  { "FileTimeToSystemTime",    (SYSCALL)0,                       0 },
          343  +#endif
          344  +
          345  +#define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \
          346  +        LPSYSTEMTIME))aSyscall[12].pCurrent)
          347  +
          348  +  { "FlushFileBuffers",        (SYSCALL)FlushFileBuffers,        0 },
          349  +
          350  +#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent)
          351  +
          352  +#if defined(SQLITE_WIN32_HAS_ANSI)
          353  +  { "FormatMessageA",          (SYSCALL)FormatMessageA,          0 },
          354  +#else
          355  +  { "FormatMessageA",          (SYSCALL)0,                       0 },
          356  +#endif
          357  +
          358  +#define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \
          359  +        DWORD,va_list*))aSyscall[14].pCurrent)
          360  +
          361  +#if defined(SQLITE_WIN32_HAS_WIDE)
          362  +  { "FormatMessageW",          (SYSCALL)FormatMessageW,          0 },
          363  +#else
          364  +  { "FormatMessageW",          (SYSCALL)0,                       0 },
          365  +#endif
          366  +
          367  +#define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
          368  +        DWORD,va_list*))aSyscall[15].pCurrent)
          369  +
          370  +  { "FreeLibrary",             (SYSCALL)FreeLibrary,             0 },
          371  +
          372  +#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[16].pCurrent)
          373  +
          374  +  { "GetCurrentProcessId",     (SYSCALL)GetCurrentProcessId,     0 },
          375  +
          376  +#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[17].pCurrent)
          377  +
          378  +#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
          379  +  { "GetDiskFreeSpaceA",       (SYSCALL)GetDiskFreeSpaceA,       0 },
          380  +#else
          381  +  { "GetDiskFreeSpaceA",       (SYSCALL)0,                       0 },
          382  +#endif
          383  +
          384  +#define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \
          385  +        LPDWORD))aSyscall[18].pCurrent)
          386  +
          387  +#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
          388  +  { "GetDiskFreeSpaceW",       (SYSCALL)GetDiskFreeSpaceW,       0 },
          389  +#else
          390  +  { "GetDiskFreeSpaceW",       (SYSCALL)0,                       0 },
          391  +#endif
          392  +
          393  +#define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \
          394  +        LPDWORD))aSyscall[19].pCurrent)
          395  +
          396  +#if defined(SQLITE_WIN32_HAS_ANSI)
          397  +  { "GetFileAttributesA",      (SYSCALL)GetFileAttributesA,      0 },
          398  +#else
          399  +  { "GetFileAttributesA",      (SYSCALL)0,                       0 },
          400  +#endif
          401  +
          402  +#define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[20].pCurrent)
          403  +
          404  +#if defined(SQLITE_WIN32_HAS_WIDE)
          405  +  { "GetFileAttributesW",      (SYSCALL)GetFileAttributesW,      0 },
          406  +#else
          407  +  { "GetFileAttributesW",      (SYSCALL)0,                       0 },
          408  +#endif
          409  +
          410  +#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[21].pCurrent)
          411  +
          412  +#if defined(SQLITE_WIN32_HAS_WIDE)
          413  +  { "GetFileAttributesExW",    (SYSCALL)GetFileAttributesExW,    0 },
          414  +#else
          415  +  { "GetFileAttributesExW",    (SYSCALL)0,                       0 },
          416  +#endif
          417  +
          418  +#define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
          419  +        LPVOID))aSyscall[22].pCurrent)
          420  +
          421  +  { "GetFileSize",             (SYSCALL)GetFileSize,             0 },
          422  +
          423  +#define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[23].pCurrent)
          424  +
          425  +#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
          426  +  { "GetFullPathNameA",        (SYSCALL)GetFullPathNameA,        0 },
          427  +#else
          428  +  { "GetFullPathNameA",        (SYSCALL)0,                       0 },
          429  +#endif
          430  +
          431  +#define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \
          432  +        LPSTR*))aSyscall[24].pCurrent)
          433  +
          434  +#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
          435  +  { "GetFullPathNameW",        (SYSCALL)GetFullPathNameW,        0 },
          436  +#else
          437  +  { "GetFullPathNameW",        (SYSCALL)0,                       0 },
          438  +#endif
          439  +
          440  +#define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
          441  +        LPWSTR*))aSyscall[25].pCurrent)
          442  +
          443  +  { "GetLastError",            (SYSCALL)GetLastError,            0 },
          444  +
          445  +#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent)
          446  +
          447  +#if SQLITE_OS_WINCE
          448  +  /* The GetProcAddressA() routine is only available on Windows CE. */
          449  +  { "GetProcAddressA",         (SYSCALL)GetProcAddressA,         0 },
          450  +#else
          451  +  /* All other Windows platforms expect GetProcAddress() to take
          452  +  ** an ANSI string regardless of the _UNICODE setting */
          453  +  { "GetProcAddressA",         (SYSCALL)GetProcAddress,          0 },
          454  +#endif
          455  +
          456  +#define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
          457  +        LPCSTR))aSyscall[27].pCurrent)
          458  +
          459  +  { "GetSystemInfo",           (SYSCALL)GetSystemInfo,           0 },
          460  +
          461  +#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[28].pCurrent)
          462  +
          463  +  { "GetSystemTime",           (SYSCALL)GetSystemTime,           0 },
          464  +
          465  +#define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[29].pCurrent)
          466  +
          467  +#if !SQLITE_OS_WINCE
          468  +  { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
          469  +#else
          470  +  { "GetSystemTimeAsFileTime", (SYSCALL)0,                       0 },
          471  +#endif
          472  +
          473  +#define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
          474  +        LPFILETIME))aSyscall[30].pCurrent)
          475  +
          476  +#if defined(SQLITE_WIN32_HAS_ANSI)
          477  +  { "GetTempPathA",            (SYSCALL)GetTempPathA,            0 },
          478  +#else
          479  +  { "GetTempPathA",            (SYSCALL)0,                       0 },
          480  +#endif
          481  +
          482  +#define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[31].pCurrent)
          483  +
          484  +#if defined(SQLITE_WIN32_HAS_WIDE)
          485  +  { "GetTempPathW",            (SYSCALL)GetTempPathW,            0 },
          486  +#else
          487  +  { "GetTempPathW",            (SYSCALL)0,                       0 },
          488  +#endif
          489  +
          490  +#define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent)
          491  +
          492  +  { "GetTickCount",            (SYSCALL)GetTickCount,            0 },
          493  +
          494  +#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent)
          495  +
          496  +#if defined(SQLITE_WIN32_HAS_ANSI)
          497  +  { "GetVersionExA",           (SYSCALL)GetVersionExA,           0 },
          498  +#else
          499  +  { "GetVersionExA",           (SYSCALL)0,                       0 },
          500  +#endif
          501  +
          502  +#define osGetVersionExA ((BOOL(WINAPI*)( \
          503  +        LPOSVERSIONINFOA))aSyscall[34].pCurrent)
          504  +
          505  +  { "HeapAlloc",               (SYSCALL)HeapAlloc,               0 },
          506  +
          507  +#define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
          508  +        SIZE_T))aSyscall[35].pCurrent)
          509  +
          510  +  { "HeapCreate",              (SYSCALL)HeapCreate,              0 },
          511  +
          512  +#define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
          513  +        SIZE_T))aSyscall[36].pCurrent)
          514  +
          515  +  { "HeapDestroy",             (SYSCALL)HeapDestroy,             0 },
          516  +
          517  +#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[37].pCurrent)
          518  +
          519  +  { "HeapFree",                (SYSCALL)HeapFree,                0 },
          520  +
          521  +#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[38].pCurrent)
          522  +
          523  +  { "HeapReAlloc",             (SYSCALL)HeapReAlloc,             0 },
          524  +
          525  +#define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
          526  +        SIZE_T))aSyscall[39].pCurrent)
          527  +
          528  +  { "HeapSize",                (SYSCALL)HeapSize,                0 },
          529  +
          530  +#define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
          531  +        LPCVOID))aSyscall[40].pCurrent)
          532  +
          533  +  { "HeapValidate",            (SYSCALL)HeapValidate,            0 },
          534  +
          535  +#define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
          536  +        LPCVOID))aSyscall[41].pCurrent)
          537  +
          538  +#if defined(SQLITE_WIN32_HAS_ANSI)
          539  +  { "LoadLibraryA",            (SYSCALL)LoadLibraryA,            0 },
          540  +#else
          541  +  { "LoadLibraryA",            (SYSCALL)0,                       0 },
          542  +#endif
          543  +
          544  +#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[42].pCurrent)
          545  +
          546  +#if defined(SQLITE_WIN32_HAS_WIDE)
          547  +  { "LoadLibraryW",            (SYSCALL)LoadLibraryW,            0 },
          548  +#else
          549  +  { "LoadLibraryW",            (SYSCALL)0,                       0 },
          550  +#endif
          551  +
          552  +#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[43].pCurrent)
          553  +
          554  +  { "LocalFree",               (SYSCALL)LocalFree,               0 },
          555  +
          556  +#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[44].pCurrent)
          557  +
          558  +#if !SQLITE_OS_WINCE
          559  +  { "LockFile",                (SYSCALL)LockFile,                0 },
          560  +
          561  +#define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
          562  +        DWORD))aSyscall[45].pCurrent)
          563  +#else
          564  +  { "LockFile",                (SYSCALL)0,                       0 },
          565  +#endif
          566  +
          567  +#if !SQLITE_OS_WINCE
          568  +  { "LockFileEx",              (SYSCALL)LockFileEx,              0 },
          569  +
          570  +#define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
          571  +        LPOVERLAPPED))aSyscall[46].pCurrent)
          572  +#else
          573  +  { "LockFileEx",              (SYSCALL)0,                       0 },
          574  +#endif
          575  +
          576  +  { "MapViewOfFile",           (SYSCALL)MapViewOfFile,           0 },
          577  +
          578  +#define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
          579  +        SIZE_T))aSyscall[47].pCurrent)
          580  +
          581  +  { "MultiByteToWideChar",     (SYSCALL)MultiByteToWideChar,     0 },
          582  +
          583  +#define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
          584  +        int))aSyscall[48].pCurrent)
          585  +
          586  +  { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
          587  +
          588  +#define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
          589  +        LARGE_INTEGER*))aSyscall[49].pCurrent)
          590  +
          591  +  { "ReadFile",                (SYSCALL)ReadFile,                0 },
          592  +
          593  +#define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
          594  +        LPOVERLAPPED))aSyscall[50].pCurrent)
          595  +
          596  +  { "SetEndOfFile",            (SYSCALL)SetEndOfFile,            0 },
          597  +
          598  +#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
          599  +
          600  +  { "SetFilePointer",          (SYSCALL)SetFilePointer,          0 },
          601  +
          602  +#define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
          603  +        DWORD))aSyscall[52].pCurrent)
          604  +
          605  +  { "Sleep",                   (SYSCALL)Sleep,                   0 },
          606  +
          607  +#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[53].pCurrent)
          608  +
          609  +  { "SystemTimeToFileTime",    (SYSCALL)SystemTimeToFileTime,    0 },
          610  +
          611  +#define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
          612  +        LPFILETIME))aSyscall[54].pCurrent)
          613  +
          614  +#if !SQLITE_OS_WINCE
          615  +  { "UnlockFile",              (SYSCALL)UnlockFile,              0 },
          616  +
          617  +#define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
          618  +        DWORD))aSyscall[55].pCurrent)
          619  +#else
          620  +  { "UnlockFile",              (SYSCALL)0,                       0 },
          621  +#endif
          622  +
          623  +#if !SQLITE_OS_WINCE
          624  +  { "UnlockFileEx",            (SYSCALL)UnlockFileEx,            0 },
          625  +
          626  +#define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
          627  +        LPOVERLAPPED))aSyscall[56].pCurrent)
          628  +#else
          629  +  { "UnlockFileEx",            (SYSCALL)0,                       0 },
          630  +#endif
          631  +
          632  +  { "UnmapViewOfFile",         (SYSCALL)UnmapViewOfFile,         0 },
          633  +
          634  +#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[57].pCurrent)
          635  +
          636  +  { "WideCharToMultiByte",     (SYSCALL)WideCharToMultiByte,     0 },
          637  +
          638  +#define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
          639  +        LPCSTR,LPBOOL))aSyscall[58].pCurrent)
          640  +
          641  +  { "WriteFile",               (SYSCALL)WriteFile,               0 },
          642  +
          643  +#define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
          644  +        LPOVERLAPPED))aSyscall[59].pCurrent)
          645  +
          646  +}; /* End of the overrideable system calls */
          647  +
          648  +/*
          649  +** This is the xSetSystemCall() method of sqlite3_vfs for all of the
          650  +** "win32" VFSes.  Return SQLITE_OK opon successfully updating the
          651  +** system call pointer, or SQLITE_NOTFOUND if there is no configurable
          652  +** system call named zName.
          653  +*/
          654  +static int winSetSystemCall(
          655  +  sqlite3_vfs *pNotUsed,        /* The VFS pointer.  Not used */
          656  +  const char *zName,            /* Name of system call to override */
          657  +  sqlite3_syscall_ptr pNewFunc  /* Pointer to new system call value */
          658  +){
          659  +  unsigned int i;
          660  +  int rc = SQLITE_NOTFOUND;
          661  +
          662  +  UNUSED_PARAMETER(pNotUsed);
          663  +  if( zName==0 ){
          664  +    /* If no zName is given, restore all system calls to their default
          665  +    ** settings and return NULL
          666  +    */
          667  +    rc = SQLITE_OK;
          668  +    for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
          669  +      if( aSyscall[i].pDefault ){
          670  +        aSyscall[i].pCurrent = aSyscall[i].pDefault;
          671  +      }
          672  +    }
          673  +  }else{
          674  +    /* If zName is specified, operate on only the one system call
          675  +    ** specified.
          676  +    */
          677  +    for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
          678  +      if( strcmp(zName, aSyscall[i].zName)==0 ){
          679  +        if( aSyscall[i].pDefault==0 ){
          680  +          aSyscall[i].pDefault = aSyscall[i].pCurrent;
          681  +        }
          682  +        rc = SQLITE_OK;
          683  +        if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault;
          684  +        aSyscall[i].pCurrent = pNewFunc;
          685  +        break;
          686  +      }
          687  +    }
          688  +  }
          689  +  return rc;
          690  +}
          691  +
          692  +/*
          693  +** Return the value of a system call.  Return NULL if zName is not a
          694  +** recognized system call name.  NULL is also returned if the system call
          695  +** is currently undefined.
          696  +*/
          697  +static sqlite3_syscall_ptr winGetSystemCall(
          698  +  sqlite3_vfs *pNotUsed,
          699  +  const char *zName
          700  +){
          701  +  unsigned int i;
          702  +
          703  +  UNUSED_PARAMETER(pNotUsed);
          704  +  for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
          705  +    if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent;
          706  +  }
          707  +  return 0;
          708  +}
          709  +
          710  +/*
          711  +** Return the name of the first system call after zName.  If zName==NULL
          712  +** then return the name of the first system call.  Return NULL if zName
          713  +** is the last system call or if zName is not the name of a valid
          714  +** system call.
          715  +*/
          716  +static const char *winNextSystemCall(sqlite3_vfs *p, const char *zName){
          717  +  int i = -1;
          718  +
          719  +  UNUSED_PARAMETER(p);
          720  +  if( zName ){
          721  +    for(i=0; i<ArraySize(aSyscall)-1; i++){
          722  +      if( strcmp(zName, aSyscall[i].zName)==0 ) break;
          723  +    }
          724  +  }
          725  +  for(i++; i<ArraySize(aSyscall); i++){
          726  +    if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName;
          727  +  }
          728  +  return 0;
          729  +}
   211    730   
   212    731   /*
   213    732   ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
   214    733   ** or WinCE.  Return false (zero) for Win95, Win98, or WinME.
   215    734   **
   216    735   ** Here is an interesting observation:  Win95, Win98, and WinME lack
   217    736   ** the LockFileEx() API.  But we can still statically link against that
................................................................................
   221    740   ** the LockFileEx() API.
   222    741   */
   223    742   #if SQLITE_OS_WINCE
   224    743   # define isNT()  (1)
   225    744   #else
   226    745     static int isNT(void){
   227    746       if( sqlite3_os_type==0 ){
   228         -      OSVERSIONINFO sInfo;
          747  +      OSVERSIONINFOA sInfo;
   229    748         sInfo.dwOSVersionInfoSize = sizeof(sInfo);
   230         -      GetVersionEx(&sInfo);
          749  +      osGetVersionExA(&sInfo);
   231    750         sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
   232    751       }
   233    752       return sqlite3_os_type==2;
   234    753     }
   235    754   #endif /* SQLITE_OS_WINCE */
   236    755   
   237    756   #ifdef SQLITE_WIN32_MALLOC
................................................................................
   243    762     void *p;
   244    763   
   245    764     winMemAssertMagic();
   246    765     hHeap = winMemGetHeap();
   247    766     assert( hHeap!=0 );
   248    767     assert( hHeap!=INVALID_HANDLE_VALUE );
   249    768   #ifdef SQLITE_WIN32_MALLOC_VALIDATE
   250         -  assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
          769  +  assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
   251    770   #endif
   252    771     assert( nBytes>=0 );
   253         -  p = HeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
          772  +  p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
   254    773     if( !p ){
   255    774       sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p",
   256         -        nBytes, GetLastError(), (void*)hHeap);
          775  +                nBytes, osGetLastError(), (void*)hHeap);
   257    776     }
   258    777     return p;
   259    778   }
   260    779   
   261    780   /*
   262    781   ** Free memory.
   263    782   */
................................................................................
   265    784     HANDLE hHeap;
   266    785   
   267    786     winMemAssertMagic();
   268    787     hHeap = winMemGetHeap();
   269    788     assert( hHeap!=0 );
   270    789     assert( hHeap!=INVALID_HANDLE_VALUE );
   271    790   #ifdef SQLITE_WIN32_MALLOC_VALIDATE
   272         -  assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
          791  +  assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
   273    792   #endif
   274    793     if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
   275         -  if( !HeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
          794  +  if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
   276    795       sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p",
   277         -        pPrior, GetLastError(), (void*)hHeap);
          796  +                pPrior, osGetLastError(), (void*)hHeap);
   278    797     }
   279    798   }
   280    799   
   281    800   /*
   282    801   ** Change the size of an existing memory allocation
   283    802   */
   284    803   static void *winMemRealloc(void *pPrior, int nBytes){
................................................................................
   286    805     void *p;
   287    806   
   288    807     winMemAssertMagic();
   289    808     hHeap = winMemGetHeap();
   290    809     assert( hHeap!=0 );
   291    810     assert( hHeap!=INVALID_HANDLE_VALUE );
   292    811   #ifdef SQLITE_WIN32_MALLOC_VALIDATE
   293         -  assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
          812  +  assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
   294    813   #endif
   295    814     assert( nBytes>=0 );
   296    815     if( !pPrior ){
   297         -    p = HeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
          816  +    p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
   298    817     }else{
   299         -    p = HeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes);
          818  +    p = osHeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes);
   300    819     }
   301    820     if( !p ){
   302    821       sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%d), heap=%p",
   303         -        pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, GetLastError(),
   304         -        (void*)hHeap);
          822  +                pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, osGetLastError(),
          823  +                (void*)hHeap);
   305    824     }
   306    825     return p;
   307    826   }
   308    827   
   309    828   /*
   310    829   ** Return the size of an outstanding allocation, in bytes.
   311    830   */
................................................................................
   314    833     SIZE_T n;
   315    834   
   316    835     winMemAssertMagic();
   317    836     hHeap = winMemGetHeap();
   318    837     assert( hHeap!=0 );
   319    838     assert( hHeap!=INVALID_HANDLE_VALUE );
   320    839   #ifdef SQLITE_WIN32_MALLOC_VALIDATE
   321         -  assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
          840  +  assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
   322    841   #endif
   323    842     if( !p ) return 0;
   324         -  n = HeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
          843  +  n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
   325    844     if( n==(SIZE_T)-1 ){
   326    845       sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p",
   327         -        p, GetLastError(), (void*)hHeap);
          846  +                p, osGetLastError(), (void*)hHeap);
   328    847       return 0;
   329    848     }
   330    849     return (int)n;
   331    850   }
   332    851   
   333    852   /*
   334    853   ** Round up a request size to the next valid allocation size.
................................................................................
   342    861   */
   343    862   static int winMemInit(void *pAppData){
   344    863     winMemData *pWinMemData = (winMemData *)pAppData;
   345    864   
   346    865     if( !pWinMemData ) return SQLITE_ERROR;
   347    866     assert( pWinMemData->magic==WINMEM_MAGIC );
   348    867     if( !pWinMemData->hHeap ){
   349         -    pWinMemData->hHeap = HeapCreate(SQLITE_WIN32_HEAP_FLAGS,
   350         -                                    SQLITE_WIN32_HEAP_INIT_SIZE,
   351         -                                    SQLITE_WIN32_HEAP_MAX_SIZE);
          868  +    pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
          869  +                                      SQLITE_WIN32_HEAP_INIT_SIZE,
          870  +                                      SQLITE_WIN32_HEAP_MAX_SIZE);
   352    871       if( !pWinMemData->hHeap ){
   353    872         sqlite3_log(SQLITE_NOMEM,
   354    873             "failed to HeapCreate (%d), flags=%u, initSize=%u, maxSize=%u",
   355         -          GetLastError(), SQLITE_WIN32_HEAP_FLAGS, SQLITE_WIN32_HEAP_INIT_SIZE,
   356         -          SQLITE_WIN32_HEAP_MAX_SIZE);
          874  +          osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
          875  +          SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
   357    876         return SQLITE_NOMEM;
   358    877       }
   359    878       pWinMemData->bOwned = TRUE;
   360    879     }
   361    880     assert( pWinMemData->hHeap!=0 );
   362    881     assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
   363    882   #ifdef SQLITE_WIN32_MALLOC_VALIDATE
   364         -  assert( HeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
          883  +  assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
   365    884   #endif
   366    885     return SQLITE_OK;
   367    886   }
   368    887   
   369    888   /*
   370    889   ** Deinitialize this module.
   371    890   */
................................................................................
   372    891   static void winMemShutdown(void *pAppData){
   373    892     winMemData *pWinMemData = (winMemData *)pAppData;
   374    893   
   375    894     if( !pWinMemData ) return;
   376    895     if( pWinMemData->hHeap ){
   377    896       assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
   378    897   #ifdef SQLITE_WIN32_MALLOC_VALIDATE
   379         -    assert( HeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
          898  +    assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
   380    899   #endif
   381    900       if( pWinMemData->bOwned ){
   382         -      if( !HeapDestroy(pWinMemData->hHeap) ){
          901  +      if( !osHeapDestroy(pWinMemData->hHeap) ){
   383    902           sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p",
   384         -            GetLastError(), (void*)pWinMemData->hHeap);
          903  +                    osGetLastError(), (void*)pWinMemData->hHeap);
   385    904         }
   386    905         pWinMemData->bOwned = FALSE;
   387    906       }
   388    907       pWinMemData->hHeap = NULL;
   389    908     }
   390    909   }
   391    910   
................................................................................
   413    932   
   414    933   void sqlite3MemSetDefault(void){
   415    934     sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetWin32());
   416    935   }
   417    936   #endif /* SQLITE_WIN32_MALLOC */
   418    937   
   419    938   /*
   420         -** Convert a UTF-8 string to microsoft unicode (UTF-16?). 
          939  +** Convert a UTF-8 string to Microsoft Unicode (UTF-16?). 
   421    940   **
   422    941   ** Space to hold the returned string is obtained from malloc.
   423    942   */
   424         -static WCHAR *utf8ToUnicode(const char *zFilename){
          943  +static LPWSTR utf8ToUnicode(const char *zFilename){
   425    944     int nChar;
   426         -  WCHAR *zWideFilename;
          945  +  LPWSTR zWideFilename;
   427    946   
   428         -  nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
          947  +  nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
   429    948     zWideFilename = malloc( nChar*sizeof(zWideFilename[0]) );
   430    949     if( zWideFilename==0 ){
   431    950       return 0;
   432    951     }
   433         -  nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, nChar);
          952  +  nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename,
          953  +                                nChar);
   434    954     if( nChar==0 ){
   435    955       free(zWideFilename);
   436    956       zWideFilename = 0;
   437    957     }
   438    958     return zWideFilename;
   439    959   }
   440    960   
   441    961   /*
   442         -** Convert microsoft unicode to UTF-8.  Space to hold the returned string is
          962  +** Convert Microsoft Unicode to UTF-8.  Space to hold the returned string is
   443    963   ** obtained from malloc().
   444    964   */
   445         -static char *unicodeToUtf8(const WCHAR *zWideFilename){
          965  +static char *unicodeToUtf8(LPCWSTR zWideFilename){
   446    966     int nByte;
   447    967     char *zFilename;
   448    968   
   449         -  nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
          969  +  nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
   450    970     zFilename = malloc( nByte );
   451    971     if( zFilename==0 ){
   452    972       return 0;
   453    973     }
   454         -  nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
   455         -                              0, 0);
          974  +  nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
          975  +                                0, 0);
   456    976     if( nByte == 0 ){
   457    977       free(zFilename);
   458    978       zFilename = 0;
   459    979     }
   460    980     return zFilename;
   461    981   }
   462    982   
   463    983   /*
   464         -** Convert an ansi string to microsoft unicode, based on the
          984  +** Convert an ansi string to Microsoft Unicode, based on the
   465    985   ** current codepage settings for file apis.
   466    986   ** 
   467    987   ** Space to hold the returned string is obtained
   468    988   ** from malloc.
   469    989   */
   470         -static WCHAR *mbcsToUnicode(const char *zFilename){
          990  +static LPWSTR mbcsToUnicode(const char *zFilename){
   471    991     int nByte;
   472         -  WCHAR *zMbcsFilename;
   473         -  int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
          992  +  LPWSTR zMbcsFilename;
          993  +  int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP;
   474    994   
   475         -  nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, NULL,0)*sizeof(WCHAR);
          995  +  nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, NULL,
          996  +                                0)*sizeof(WCHAR);
   476    997     zMbcsFilename = malloc( nByte*sizeof(zMbcsFilename[0]) );
   477    998     if( zMbcsFilename==0 ){
   478    999       return 0;
   479   1000     }
   480         -  nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte);
         1001  +  nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename,
         1002  +                                nByte);
   481   1003     if( nByte==0 ){
   482   1004       free(zMbcsFilename);
   483   1005       zMbcsFilename = 0;
   484   1006     }
   485   1007     return zMbcsFilename;
   486   1008   }
   487   1009   
   488   1010   /*
   489         -** Convert microsoft unicode to multibyte character string, based on the
   490         -** user's Ansi codepage.
         1011  +** Convert Microsoft Unicode to multi-byte character string, based on the
         1012  +** user's ANSI codepage.
   491   1013   **
   492   1014   ** Space to hold the returned string is obtained from
   493   1015   ** malloc().
   494   1016   */
   495         -static char *unicodeToMbcs(const WCHAR *zWideFilename){
         1017  +static char *unicodeToMbcs(LPCWSTR zWideFilename){
   496   1018     int nByte;
   497   1019     char *zFilename;
   498         -  int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
         1020  +  int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP;
   499   1021   
   500         -  nByte = WideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0);
         1022  +  nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0);
   501   1023     zFilename = malloc( nByte );
   502   1024     if( zFilename==0 ){
   503   1025       return 0;
   504   1026     }
   505         -  nByte = WideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename, nByte,
   506         -                              0, 0);
         1027  +  nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename,
         1028  +                                nByte, 0, 0);
   507   1029     if( nByte == 0 ){
   508   1030       free(zFilename);
   509   1031       zFilename = 0;
   510   1032     }
   511   1033     return zFilename;
   512   1034   }
   513   1035   
   514   1036   /*
   515   1037   ** Convert multibyte character string to UTF-8.  Space to hold the
   516   1038   ** returned string is obtained from malloc().
   517   1039   */
   518   1040   char *sqlite3_win32_mbcs_to_utf8(const char *zFilename){
   519   1041     char *zFilenameUtf8;
   520         -  WCHAR *zTmpWide;
         1042  +  LPWSTR zTmpWide;
   521   1043   
   522   1044     zTmpWide = mbcsToUnicode(zFilename);
   523   1045     if( zTmpWide==0 ){
   524   1046       return 0;
   525   1047     }
   526   1048     zFilenameUtf8 = unicodeToUtf8(zTmpWide);
   527   1049     free(zTmpWide);
................................................................................
   530   1052   
   531   1053   /*
   532   1054   ** Convert UTF-8 to multibyte character string.  Space to hold the 
   533   1055   ** returned string is obtained from malloc().
   534   1056   */
   535   1057   char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){
   536   1058     char *zFilenameMbcs;
   537         -  WCHAR *zTmpWide;
         1059  +  LPWSTR zTmpWide;
   538   1060   
   539   1061     zTmpWide = utf8ToUnicode(zFilename);
   540   1062     if( zTmpWide==0 ){
   541   1063       return 0;
   542   1064     }
   543   1065     zFilenameMbcs = unicodeToMbcs(zTmpWide);
   544   1066     free(zTmpWide);
................................................................................
   556   1078     ** returns the number of TCHARs written to the output
   557   1079     ** buffer, excluding the terminating null char.
   558   1080     */
   559   1081     DWORD dwLen = 0;
   560   1082     char *zOut = 0;
   561   1083   
   562   1084     if( isNT() ){
   563         -    WCHAR *zTempWide = NULL;
   564         -    dwLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
   565         -                           FORMAT_MESSAGE_FROM_SYSTEM |
   566         -                           FORMAT_MESSAGE_IGNORE_INSERTS,
   567         -                           NULL,
   568         -                           lastErrno,
   569         -                           0,
   570         -                           (LPWSTR) &zTempWide,
   571         -                           0,
   572         -                           0);
         1085  +    LPWSTR zTempWide = NULL;
         1086  +    dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
         1087  +                             FORMAT_MESSAGE_FROM_SYSTEM |
         1088  +                             FORMAT_MESSAGE_IGNORE_INSERTS,
         1089  +                             NULL,
         1090  +                             lastErrno,
         1091  +                             0,
         1092  +                             (LPWSTR) &zTempWide,
         1093  +                             0,
         1094  +                             0);
   573   1095       if( dwLen > 0 ){
   574   1096         /* allocate a buffer and convert to UTF8 */
   575   1097         zOut = unicodeToUtf8(zTempWide);
   576   1098         /* free the system buffer allocated by FormatMessage */
   577         -      LocalFree(zTempWide);
         1099  +      osLocalFree(zTempWide);
   578   1100       }
   579   1101   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
   580   1102   ** Since the ASCII version of these Windows API do not exist for WINCE,
   581   1103   ** it's important to not reference them for WINCE builds.
   582   1104   */
   583   1105   #if SQLITE_OS_WINCE==0
   584   1106     }else{
   585   1107       char *zTemp = NULL;
   586         -    dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
   587         -                           FORMAT_MESSAGE_FROM_SYSTEM |
   588         -                           FORMAT_MESSAGE_IGNORE_INSERTS,
   589         -                           NULL,
   590         -                           lastErrno,
   591         -                           0,
   592         -                           (LPSTR) &zTemp,
   593         -                           0,
   594         -                           0);
         1108  +    dwLen = osFormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
         1109  +                             FORMAT_MESSAGE_FROM_SYSTEM |
         1110  +                             FORMAT_MESSAGE_IGNORE_INSERTS,
         1111  +                             NULL,
         1112  +                             lastErrno,
         1113  +                             0,
         1114  +                             (LPSTR) &zTemp,
         1115  +                             0,
         1116  +                             0);
   595   1117       if( dwLen > 0 ){
   596   1118         /* allocate a buffer and convert to UTF8 */
   597   1119         zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
   598   1120         /* free the system buffer allocated by FormatMessage */
   599         -      LocalFree(zTemp);
         1121  +      osLocalFree(zTemp);
   600   1122       }
   601   1123   #endif
   602   1124     }
   603   1125     if( 0 == dwLen ){
   604   1126       sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", lastErrno, lastErrno);
   605   1127     }else{
   606   1128       /* copy a maximum of nBuf chars to output buffer */
................................................................................
   672   1194   ** to give up with an error.
   673   1195   */
   674   1196   static int retryIoerr(int *pnRetry){
   675   1197     DWORD e;
   676   1198     if( *pnRetry>=win32IoerrRetry ){
   677   1199       return 0;
   678   1200     }
   679         -  e = GetLastError();
         1201  +  e = osGetLastError();
   680   1202     if( e==ERROR_ACCESS_DENIED ||
   681   1203         e==ERROR_LOCK_VIOLATION ||
   682   1204         e==ERROR_SHARING_VIOLATION ){
   683         -    Sleep(win32IoerrRetryDelay*(1+*pnRetry));
         1205  +    osSleep(win32IoerrRetryDelay*(1+*pnRetry));
   684   1206       ++*pnRetry;
   685   1207       return 1;
   686   1208     }
   687   1209     return 0;
   688   1210   }
   689   1211   
   690   1212   /*
................................................................................
   700   1222   }
   701   1223   
   702   1224   #if SQLITE_OS_WINCE
   703   1225   /*************************************************************************
   704   1226   ** This section contains code for WinCE only.
   705   1227   */
   706   1228   /*
   707         -** WindowsCE does not have a localtime() function.  So create a
         1229  +** Windows CE does not have a localtime() function.  So create a
   708   1230   ** substitute.
   709   1231   */
   710   1232   #include <time.h>
   711   1233   struct tm *__cdecl localtime(const time_t *t)
   712   1234   {
   713   1235     static struct tm y;
   714   1236     FILETIME uTm, lTm;
   715   1237     SYSTEMTIME pTm;
   716   1238     sqlite3_int64 t64;
   717   1239     t64 = *t;
   718   1240     t64 = (t64 + 11644473600)*10000000;
   719   1241     uTm.dwLowDateTime = (DWORD)(t64 & 0xFFFFFFFF);
   720   1242     uTm.dwHighDateTime= (DWORD)(t64 >> 32);
   721         -  FileTimeToLocalFileTime(&uTm,&lTm);
   722         -  FileTimeToSystemTime(&lTm,&pTm);
         1243  +  osFileTimeToLocalFileTime(&uTm,&lTm);
         1244  +  osFileTimeToSystemTime(&lTm,&pTm);
   723   1245     y.tm_year = pTm.wYear - 1900;
   724   1246     y.tm_mon = pTm.wMonth - 1;
   725   1247     y.tm_wday = pTm.wDayOfWeek;
   726   1248     y.tm_mday = pTm.wDay;
   727   1249     y.tm_hour = pTm.wHour;
   728   1250     y.tm_min = pTm.wMinute;
   729   1251     y.tm_sec = pTm.wSecond;
   730   1252     return &y;
   731   1253   }
   732   1254   
   733         -/* This will never be called, but defined to make the code compile */
   734         -#define GetTempPathA(a,b)
   735         -
   736         -#define LockFile(a,b,c,d,e)       winceLockFile(&a, b, c, d, e)
   737         -#define UnlockFile(a,b,c,d,e)     winceUnlockFile(&a, b, c, d, e)
   738         -#define LockFileEx(a,b,c,d,e,f)   winceLockFileEx(&a, b, c, d, e, f)
   739         -
   740   1255   #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)]
   741   1256   
   742   1257   /*
   743   1258   ** Acquire a lock on the handle h
   744   1259   */
   745   1260   static void winceMutexAcquire(HANDLE h){
   746   1261      DWORD dwErr;
................................................................................
   754   1269   #define winceMutexRelease(h) ReleaseMutex(h)
   755   1270   
   756   1271   /*
   757   1272   ** Create the mutex and shared memory used for locking in the file
   758   1273   ** descriptor pFile
   759   1274   */
   760   1275   static BOOL winceCreateLock(const char *zFilename, winFile *pFile){
   761         -  WCHAR *zTok;
   762         -  WCHAR *zName = utf8ToUnicode(zFilename);
         1276  +  LPWSTR zTok;
         1277  +  LPWSTR zName = utf8ToUnicode(zFilename);
   763   1278     BOOL bInit = TRUE;
   764   1279   
   765   1280     /* Initialize the local lockdata */
   766         -  ZeroMemory(&pFile->local, sizeof(pFile->local));
         1281  +  memset(&pFile->local, 0, sizeof(pFile->local));
   767   1282   
   768   1283     /* Replace the backslashes from the filename and lowercase it
   769   1284     ** to derive a mutex name. */
   770         -  zTok = CharLowerW(zName);
         1285  +  zTok = osCharLowerW(zName);
   771   1286     for (;*zTok;zTok++){
   772   1287       if (*zTok == '\\') *zTok = '_';
   773   1288     }
   774   1289   
   775   1290     /* Create/open the named mutex */
   776         -  pFile->hMutex = CreateMutexW(NULL, FALSE, zName);
         1291  +  pFile->hMutex = osCreateMutexW(NULL, FALSE, zName);
   777   1292     if (!pFile->hMutex){
   778         -    pFile->lastErrno = GetLastError();
         1293  +    pFile->lastErrno = osGetLastError();
   779   1294       winLogError(SQLITE_ERROR, pFile->lastErrno, "winceCreateLock1", zFilename);
   780   1295       free(zName);
   781   1296       return FALSE;
   782   1297     }
   783   1298   
   784   1299     /* Acquire the mutex before continuing */
   785   1300     winceMutexAcquire(pFile->hMutex);
   786   1301     
   787   1302     /* Since the names of named mutexes, semaphores, file mappings etc are 
   788   1303     ** case-sensitive, take advantage of that by uppercasing the mutex name
   789   1304     ** and using that as the shared filemapping name.
   790   1305     */
   791         -  CharUpperW(zName);
   792         -  pFile->hShared = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
   793         -                                       PAGE_READWRITE, 0, sizeof(winceLock),
   794         -                                       zName);  
         1306  +  osCharUpperW(zName);
         1307  +  pFile->hShared = osCreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
         1308  +                                        PAGE_READWRITE, 0, sizeof(winceLock),
         1309  +                                        zName);  
   795   1310   
   796   1311     /* Set a flag that indicates we're the first to create the memory so it 
   797   1312     ** must be zero-initialized */
   798         -  if (GetLastError() == ERROR_ALREADY_EXISTS){
         1313  +  if (osGetLastError() == ERROR_ALREADY_EXISTS){
   799   1314       bInit = FALSE;
   800   1315     }
   801   1316   
   802   1317     free(zName);
   803   1318   
   804   1319     /* If we succeeded in making the shared memory handle, map it. */
   805   1320     if (pFile->hShared){
   806         -    pFile->shared = (winceLock*)MapViewOfFile(pFile->hShared, 
         1321  +    pFile->shared = (winceLock*)osMapViewOfFile(pFile->hShared, 
   807   1322                FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock));
   808   1323       /* If mapping failed, close the shared memory handle and erase it */
   809   1324       if (!pFile->shared){
   810         -      pFile->lastErrno = GetLastError();
         1325  +      pFile->lastErrno = osGetLastError();
   811   1326         winLogError(SQLITE_ERROR, pFile->lastErrno,
   812   1327                  "winceCreateLock2", zFilename);
   813         -      CloseHandle(pFile->hShared);
         1328  +      osCloseHandle(pFile->hShared);
   814   1329         pFile->hShared = NULL;
   815   1330       }
   816   1331     }
   817   1332   
   818   1333     /* If shared memory could not be created, then close the mutex and fail */
   819   1334     if (pFile->hShared == NULL){
   820   1335       winceMutexRelease(pFile->hMutex);
   821         -    CloseHandle(pFile->hMutex);
         1336  +    osCloseHandle(pFile->hMutex);
   822   1337       pFile->hMutex = NULL;
   823   1338       return FALSE;
   824   1339     }
   825   1340     
   826   1341     /* Initialize the shared memory if we're supposed to */
   827   1342     if (bInit) {
   828         -    ZeroMemory(pFile->shared, sizeof(winceLock));
         1343  +    memset(pFile->shared, 0, sizeof(winceLock));
   829   1344     }
   830   1345   
   831   1346     winceMutexRelease(pFile->hMutex);
   832   1347     return TRUE;
   833   1348   }
   834   1349   
   835   1350   /*
................................................................................
   852   1367         pFile->shared->bPending = FALSE;
   853   1368       }
   854   1369       if (pFile->local.bExclusive){
   855   1370         pFile->shared->bExclusive = FALSE;
   856   1371       }
   857   1372   
   858   1373       /* De-reference and close our copy of the shared memory handle */
   859         -    UnmapViewOfFile(pFile->shared);
   860         -    CloseHandle(pFile->hShared);
         1374  +    osUnmapViewOfFile(pFile->shared);
         1375  +    osCloseHandle(pFile->hShared);
   861   1376   
   862   1377       /* Done with the mutex */
   863   1378       winceMutexRelease(pFile->hMutex);    
   864         -    CloseHandle(pFile->hMutex);
         1379  +    osCloseHandle(pFile->hMutex);
   865   1380       pFile->hMutex = NULL;
   866   1381     }
   867   1382   }
   868   1383   
   869   1384   /* 
   870         -** An implementation of the LockFile() API of windows for wince
         1385  +** An implementation of the LockFile() API of Windows for CE
   871   1386   */
   872   1387   static BOOL winceLockFile(
   873   1388     HANDLE *phFile,
   874   1389     DWORD dwFileOffsetLow,
   875   1390     DWORD dwFileOffsetHigh,
   876   1391     DWORD nNumberOfBytesToLockLow,
   877   1392     DWORD nNumberOfBytesToLockHigh
................................................................................
   927   1442     }
   928   1443   
   929   1444     winceMutexRelease(pFile->hMutex);
   930   1445     return bReturn;
   931   1446   }
   932   1447   
   933   1448   /*
   934         -** An implementation of the UnlockFile API of windows for wince
         1449  +** An implementation of the UnlockFile API of Windows for CE
   935   1450   */
   936   1451   static BOOL winceUnlockFile(
   937   1452     HANDLE *phFile,
   938   1453     DWORD dwFileOffsetLow,
   939   1454     DWORD dwFileOffsetHigh,
   940   1455     DWORD nNumberOfBytesToUnlockLow,
   941   1456     DWORD nNumberOfBytesToUnlockHigh
................................................................................
   989   1504     }
   990   1505   
   991   1506     winceMutexRelease(pFile->hMutex);
   992   1507     return bReturn;
   993   1508   }
   994   1509   
   995   1510   /*
   996         -** An implementation of the LockFileEx() API of windows for wince
         1511  +** An implementation of the LockFileEx() API of Windows for CE
   997   1512   */
   998   1513   static BOOL winceLockFileEx(
   999   1514     HANDLE *phFile,
  1000   1515     DWORD dwFlags,
  1001   1516     DWORD dwReserved,
  1002   1517     DWORD nNumberOfBytesToLockLow,
  1003   1518     DWORD nNumberOfBytesToLockHigh,
................................................................................
  1022   1537   
  1023   1538   /*****************************************************************************
  1024   1539   ** The next group of routines implement the I/O methods specified
  1025   1540   ** by the sqlite3_io_methods object.
  1026   1541   ******************************************************************************/
  1027   1542   
  1028   1543   /*
  1029         -** Some microsoft compilers lack this definition.
         1544  +** Some Microsoft compilers lack this definition.
  1030   1545   */
  1031   1546   #ifndef INVALID_SET_FILE_POINTER
  1032   1547   # define INVALID_SET_FILE_POINTER ((DWORD)-1)
  1033   1548   #endif
  1034   1549   
  1035   1550   /*
  1036   1551   ** Move the current position of the file handle passed as the first 
................................................................................
  1048   1563     /* API oddity: If successful, SetFilePointer() returns a dword 
  1049   1564     ** containing the lower 32-bits of the new file-offset. Or, if it fails,
  1050   1565     ** it returns INVALID_SET_FILE_POINTER. However according to MSDN, 
  1051   1566     ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine 
  1052   1567     ** whether an error has actually occured, it is also necessary to call 
  1053   1568     ** GetLastError().
  1054   1569     */
  1055         -  dwRet = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
  1056         -  if( (dwRet==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR) ){
  1057         -    pFile->lastErrno = GetLastError();
         1570  +  dwRet = osSetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
         1571  +  if( (dwRet==INVALID_SET_FILE_POINTER && osGetLastError()!=NO_ERROR) ){
         1572  +    pFile->lastErrno = osGetLastError();
  1058   1573       winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
  1059   1574                "seekWinFile", pFile->zPath);
  1060   1575       return 1;
  1061   1576     }
  1062   1577   
  1063   1578     return 0;
  1064   1579   }
  1065   1580   
  1066   1581   /*
  1067   1582   ** Close a file.
  1068   1583   **
  1069   1584   ** It is reported that an attempt to close a handle might sometimes
  1070         -** fail.  This is a very unreasonable result, but windows is notorious
         1585  +** fail.  This is a very unreasonable result, but Windows is notorious
  1071   1586   ** for being unreasonable so I do not doubt that it might happen.  If
  1072   1587   ** the close fails, we pause for 100 milliseconds and try again.  As
  1073   1588   ** many as MX_CLOSE_ATTEMPT attempts to close the handle are made before
  1074   1589   ** giving up and returning an error.
  1075   1590   */
  1076   1591   #define MX_CLOSE_ATTEMPT 3
  1077   1592   static int winClose(sqlite3_file *id){
................................................................................
  1078   1593     int rc, cnt = 0;
  1079   1594     winFile *pFile = (winFile*)id;
  1080   1595   
  1081   1596     assert( id!=0 );
  1082   1597     assert( pFile->pShm==0 );
  1083   1598     OSTRACE(("CLOSE %d\n", pFile->h));
  1084   1599     do{
  1085         -    rc = CloseHandle(pFile->h);
         1600  +    rc = osCloseHandle(pFile->h);
  1086   1601       /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
  1087         -  }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (Sleep(100), 1) );
         1602  +  }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (osSleep(100), 1) );
  1088   1603   #if SQLITE_OS_WINCE
  1089   1604   #define WINCE_DELETION_ATTEMPTS 3
  1090   1605     winceDestroyLock(pFile);
  1091   1606     if( pFile->zDeleteOnClose ){
  1092   1607       int cnt = 0;
  1093   1608       while(
  1094         -           DeleteFileW(pFile->zDeleteOnClose)==0
  1095         -        && GetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff 
         1609  +           osDeleteFileW(pFile->zDeleteOnClose)==0
         1610  +        && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff 
  1096   1611           && cnt++ < WINCE_DELETION_ATTEMPTS
  1097   1612       ){
  1098         -       Sleep(100);  /* Wait a little before trying again */
         1613  +       osSleep(100);  /* Wait a little before trying again */
  1099   1614       }
  1100   1615       free(pFile->zDeleteOnClose);
  1101   1616     }
  1102   1617   #endif
  1103   1618     OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed"));
  1104   1619     OpenCounter(-1);
  1105   1620     return rc ? SQLITE_OK
  1106         -            : winLogError(SQLITE_IOERR_CLOSE, GetLastError(),
         1621  +            : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(),
  1107   1622                             "winClose", pFile->zPath);
  1108   1623   }
  1109   1624   
  1110   1625   /*
  1111   1626   ** Read data from a file into a buffer.  Return SQLITE_OK if all
  1112   1627   ** bytes were read successfully and SQLITE_IOERR if anything goes
  1113   1628   ** wrong.
................................................................................
  1125   1640     assert( id!=0 );
  1126   1641     SimulateIOError(return SQLITE_IOERR_READ);
  1127   1642     OSTRACE(("READ %d lock=%d\n", pFile->h, pFile->locktype));
  1128   1643   
  1129   1644     if( seekWinFile(pFile, offset) ){
  1130   1645       return SQLITE_FULL;
  1131   1646     }
  1132         -  while( !ReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
         1647  +  while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
  1133   1648       if( retryIoerr(&nRetry) ) continue;
  1134         -    pFile->lastErrno = GetLastError();
         1649  +    pFile->lastErrno = osGetLastError();
  1135   1650       return winLogError(SQLITE_IOERR_READ, pFile->lastErrno,
  1136   1651                "winRead", pFile->zPath);
  1137   1652     }
  1138   1653     logIoerr(nRetry);
  1139   1654     if( nRead<(DWORD)amt ){
  1140   1655       /* Unread parts of the buffer must be zero-filled */
  1141   1656       memset(&((char*)pBuf)[nRead], 0, amt-nRead);
................................................................................
  1169   1684     rc = seekWinFile(pFile, offset);
  1170   1685     if( rc==0 ){
  1171   1686       u8 *aRem = (u8 *)pBuf;        /* Data yet to be written */
  1172   1687       int nRem = amt;               /* Number of bytes yet to be written */
  1173   1688       DWORD nWrite;                 /* Bytes written by each WriteFile() call */
  1174   1689   
  1175   1690       while( nRem>0 ){
  1176         -      if( !WriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
         1691  +      if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
  1177   1692           if( retryIoerr(&nRetry) ) continue;
  1178   1693           break;
  1179   1694         }
  1180   1695         if( nWrite<=0 ) break;
  1181   1696         aRem += nWrite;
  1182   1697         nRem -= nWrite;
  1183   1698       }
  1184   1699       if( nRem>0 ){
  1185         -      pFile->lastErrno = GetLastError();
         1700  +      pFile->lastErrno = osGetLastError();
  1186   1701         rc = 1;
  1187   1702       }
  1188   1703     }
  1189   1704   
  1190   1705     if( rc ){
  1191   1706       if(   ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL )
  1192   1707          || ( pFile->lastErrno==ERROR_DISK_FULL )){
................................................................................
  1221   1736       nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
  1222   1737     }
  1223   1738   
  1224   1739     /* SetEndOfFile() returns non-zero when successful, or zero when it fails. */
  1225   1740     if( seekWinFile(pFile, nByte) ){
  1226   1741       rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno,
  1227   1742                "winTruncate1", pFile->zPath);
  1228         -  }else if( 0==SetEndOfFile(pFile->h) ){
  1229         -    pFile->lastErrno = GetLastError();
         1743  +  }else if( 0==osSetEndOfFile(pFile->h) ){
         1744  +    pFile->lastErrno = osGetLastError();
  1230   1745       rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno,
  1231   1746                "winTruncate2", pFile->zPath);
  1232   1747     }
  1233   1748   
  1234   1749     OSTRACE(("TRUNCATE %d %lld %s\n", pFile->h, nByte, rc ? "failed" : "ok"));
  1235   1750     return rc;
  1236   1751   }
................................................................................
  1289   1804   
  1290   1805     /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
  1291   1806     ** no-op
  1292   1807     */
  1293   1808   #ifdef SQLITE_NO_SYNC
  1294   1809     return SQLITE_OK;
  1295   1810   #else
  1296         -  rc = FlushFileBuffers(pFile->h);
         1811  +  rc = osFlushFileBuffers(pFile->h);
  1297   1812     SimulateIOError( rc=FALSE );
  1298   1813     if( rc ){
  1299   1814       return SQLITE_OK;
  1300   1815     }else{
  1301         -    pFile->lastErrno = GetLastError();
         1816  +    pFile->lastErrno = osGetLastError();
  1302   1817       return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno,
  1303   1818                "winSync", pFile->zPath);
  1304   1819     }
  1305   1820   #endif
  1306   1821   }
  1307   1822   
  1308   1823   /*
................................................................................
  1312   1827     DWORD upperBits;
  1313   1828     DWORD lowerBits;
  1314   1829     winFile *pFile = (winFile*)id;
  1315   1830     DWORD error;
  1316   1831   
  1317   1832     assert( id!=0 );
  1318   1833     SimulateIOError(return SQLITE_IOERR_FSTAT);
  1319         -  lowerBits = GetFileSize(pFile->h, &upperBits);
         1834  +  lowerBits = osGetFileSize(pFile->h, &upperBits);
  1320   1835     if(   (lowerBits == INVALID_FILE_SIZE)
  1321         -     && ((error = GetLastError()) != NO_ERROR) )
         1836  +     && ((error = osGetLastError()) != NO_ERROR) )
  1322   1837     {
  1323   1838       pFile->lastErrno = error;
  1324   1839       return winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
  1325   1840                "winFileSize", pFile->zPath);
  1326   1841     }
  1327   1842     *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits;
  1328   1843     return SQLITE_OK;
................................................................................
  1343   1858   static int getReadLock(winFile *pFile){
  1344   1859     int res;
  1345   1860     if( isNT() ){
  1346   1861       OVERLAPPED ovlp;
  1347   1862       ovlp.Offset = SHARED_FIRST;
  1348   1863       ovlp.OffsetHigh = 0;
  1349   1864       ovlp.hEvent = 0;
  1350         -    res = LockFileEx(pFile->h, LOCKFILE_FAIL_IMMEDIATELY,
  1351         -                     0, SHARED_SIZE, 0, &ovlp);
         1865  +    res = osLockFileEx(pFile->h, LOCKFILE_FAIL_IMMEDIATELY,
         1866  +                       0, SHARED_SIZE, 0, &ovlp);
  1352   1867   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  1353   1868   */
  1354   1869   #if SQLITE_OS_WINCE==0
  1355   1870     }else{
  1356   1871       int lk;
  1357   1872       sqlite3_randomness(sizeof(lk), &lk);
  1358   1873       pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
  1359         -    res = LockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
         1874  +    res = osLockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
  1360   1875   #endif
  1361   1876     }
  1362   1877     if( res == 0 ){
  1363         -    pFile->lastErrno = GetLastError();
         1878  +    pFile->lastErrno = osGetLastError();
  1364   1879       /* No need to log a failure to lock */
  1365   1880     }
  1366   1881     return res;
  1367   1882   }
  1368   1883   
  1369   1884   /*
  1370   1885   ** Undo a readlock
  1371   1886   */
  1372   1887   static int unlockReadLock(winFile *pFile){
  1373   1888     int res;
  1374   1889     if( isNT() ){
  1375         -    res = UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
         1890  +    res = osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
  1376   1891   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  1377   1892   */
  1378   1893   #if SQLITE_OS_WINCE==0
  1379   1894     }else{
  1380         -    res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
         1895  +    res = osUnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
  1381   1896   #endif
  1382   1897     }
  1383         -  if( res==0 && GetLastError()!=ERROR_NOT_LOCKED ){
  1384         -    pFile->lastErrno = GetLastError();
         1898  +  if( res==0 && osGetLastError()!=ERROR_NOT_LOCKED ){
         1899  +    pFile->lastErrno = osGetLastError();
  1385   1900       winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
  1386   1901                "unlockReadLock", pFile->zPath);
  1387   1902     }
  1388   1903     return res;
  1389   1904   }
  1390   1905   
  1391   1906   /*
................................................................................
  1412   1927   ** This routine will only increase a lock.  The winUnlock() routine
  1413   1928   ** erases all locks at once and returns us immediately to locking level 0.
  1414   1929   ** It is not possible to lower the locking level one step at a time.  You
  1415   1930   ** must go straight to locking level 0.
  1416   1931   */
  1417   1932   static int winLock(sqlite3_file *id, int locktype){
  1418   1933     int rc = SQLITE_OK;    /* Return code from subroutines */
  1419         -  int res = 1;           /* Result of a windows lock call */
         1934  +  int res = 1;           /* Result of a Windows lock call */
  1420   1935     int newLocktype;       /* Set pFile->locktype to this value before exiting */
  1421   1936     int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */
  1422   1937     winFile *pFile = (winFile*)id;
  1423   1938     DWORD error = NO_ERROR;
  1424   1939   
  1425   1940     assert( id!=0 );
  1426   1941     OSTRACE(("LOCK %d %d was %d(%d)\n",
................................................................................
  1446   1961     */
  1447   1962     newLocktype = pFile->locktype;
  1448   1963     if(   (pFile->locktype==NO_LOCK)
  1449   1964        || (   (locktype==EXCLUSIVE_LOCK)
  1450   1965            && (pFile->locktype==RESERVED_LOCK))
  1451   1966     ){
  1452   1967       int cnt = 3;
  1453         -    while( cnt-->0 && (res = LockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
         1968  +    while( cnt-->0 && (res = osLockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
  1454   1969         /* Try 3 times to get the pending lock.  This is needed to work
  1455         -      ** around problems caused by anti-virus software on windows system.
         1970  +      ** around problems caused by indexing and/or anti-virus software on
         1971  +      ** Windows systems.
  1456   1972         ** If you are using this code as a model for alternative VFSes, do not
  1457         -      ** copy this retry logic.  It is a hack intended for windows only.
         1973  +      ** copy this retry logic.  It is a hack intended for Windows only.
  1458   1974         */
  1459   1975         OSTRACE(("could not get a PENDING lock. cnt=%d\n", cnt));
  1460         -      if( cnt ) Sleep(1);
         1976  +      if( cnt ) osSleep(1);
  1461   1977       }
  1462   1978       gotPendingLock = res;
  1463   1979       if( !res ){
  1464         -      error = GetLastError();
         1980  +      error = osGetLastError();
  1465   1981       }
  1466   1982     }
  1467   1983   
  1468   1984     /* Acquire a shared lock
  1469   1985     */
  1470   1986     if( locktype==SHARED_LOCK && res ){
  1471   1987       assert( pFile->locktype==NO_LOCK );
  1472   1988       res = getReadLock(pFile);
  1473   1989       if( res ){
  1474   1990         newLocktype = SHARED_LOCK;
  1475   1991       }else{
  1476         -      error = GetLastError();
         1992  +      error = osGetLastError();
  1477   1993       }
  1478   1994     }
  1479   1995   
  1480   1996     /* Acquire a RESERVED lock
  1481   1997     */
  1482   1998     if( locktype==RESERVED_LOCK && res ){
  1483   1999       assert( pFile->locktype==SHARED_LOCK );
  1484         -    res = LockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
         2000  +    res = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
  1485   2001       if( res ){
  1486   2002         newLocktype = RESERVED_LOCK;
  1487   2003       }else{
  1488         -      error = GetLastError();
         2004  +      error = osGetLastError();
  1489   2005       }
  1490   2006     }
  1491   2007   
  1492   2008     /* Acquire a PENDING lock
  1493   2009     */
  1494   2010     if( locktype==EXCLUSIVE_LOCK && res ){
  1495   2011       newLocktype = PENDING_LOCK;
................................................................................
  1498   2014   
  1499   2015     /* Acquire an EXCLUSIVE lock
  1500   2016     */
  1501   2017     if( locktype==EXCLUSIVE_LOCK && res ){
  1502   2018       assert( pFile->locktype>=SHARED_LOCK );
  1503   2019       res = unlockReadLock(pFile);
  1504   2020       OSTRACE(("unreadlock = %d\n", res));
  1505         -    res = LockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
         2021  +    res = osLockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
  1506   2022       if( res ){
  1507   2023         newLocktype = EXCLUSIVE_LOCK;
  1508   2024       }else{
  1509         -      error = GetLastError();
         2025  +      error = osGetLastError();
  1510   2026         OSTRACE(("error-code = %d\n", error));
  1511   2027         getReadLock(pFile);
  1512   2028       }
  1513   2029     }
  1514   2030   
  1515   2031     /* If we are holding a PENDING lock that ought to be released, then
  1516   2032     ** release it now.
  1517   2033     */
  1518   2034     if( gotPendingLock && locktype==SHARED_LOCK ){
  1519         -    UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
         2035  +    osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
  1520   2036     }
  1521   2037   
  1522   2038     /* Update the state of the lock has held in the file descriptor then
  1523   2039     ** return the appropriate result code.
  1524   2040     */
  1525   2041     if( res ){
  1526   2042       rc = SQLITE_OK;
................................................................................
  1546   2062     SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
  1547   2063   
  1548   2064     assert( id!=0 );
  1549   2065     if( pFile->locktype>=RESERVED_LOCK ){
  1550   2066       rc = 1;
  1551   2067       OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc));
  1552   2068     }else{
  1553         -    rc = LockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
         2069  +    rc = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
  1554   2070       if( rc ){
  1555         -      UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
         2071  +      osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
  1556   2072       }
  1557   2073       rc = !rc;
  1558   2074       OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc));
  1559   2075     }
  1560   2076     *pResOut = rc;
  1561   2077     return SQLITE_OK;
  1562   2078   }
................................................................................
  1578   2094     int rc = SQLITE_OK;
  1579   2095     assert( pFile!=0 );
  1580   2096     assert( locktype<=SHARED_LOCK );
  1581   2097     OSTRACE(("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype,
  1582   2098             pFile->locktype, pFile->sharedLockByte));
  1583   2099     type = pFile->locktype;
  1584   2100     if( type>=EXCLUSIVE_LOCK ){
  1585         -    UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
         2101  +    osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
  1586   2102       if( locktype==SHARED_LOCK && !getReadLock(pFile) ){
  1587   2103         /* This should never happen.  We should always be able to
  1588   2104         ** reacquire the read lock */
  1589         -      rc = winLogError(SQLITE_IOERR_UNLOCK, GetLastError(),
         2105  +      rc = winLogError(SQLITE_IOERR_UNLOCK, osGetLastError(),
  1590   2106                  "winUnlock", pFile->zPath);
  1591   2107       }
  1592   2108     }
  1593   2109     if( type>=RESERVED_LOCK ){
  1594         -    UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
         2110  +    osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
  1595   2111     }
  1596   2112     if( locktype==NO_LOCK && type>=SHARED_LOCK ){
  1597   2113       unlockReadLock(pFile);
  1598   2114     }
  1599   2115     if( type>=PENDING_LOCK ){
  1600         -    UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
         2116  +    osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
  1601   2117     }
  1602   2118     pFile->locktype = (u8)locktype;
  1603   2119     return rc;
  1604   2120   }
  1605   2121   
  1606   2122   /*
  1607   2123   ** Control and query of the open file handle.
................................................................................
  1830   2346     if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
  1831   2347   
  1832   2348     memset(&ovlp, 0, sizeof(OVERLAPPED));
  1833   2349     ovlp.Offset = ofst;
  1834   2350   
  1835   2351     /* Release/Acquire the system-level lock */
  1836   2352     if( lockType==_SHM_UNLCK ){
  1837         -    rc = UnlockFileEx(pFile->hFile.h, 0, nByte, 0, &ovlp);
         2353  +    rc = osUnlockFileEx(pFile->hFile.h, 0, nByte, 0, &ovlp);
  1838   2354     }else{
  1839         -    rc = LockFileEx(pFile->hFile.h, dwFlags, 0, nByte, 0, &ovlp);
         2355  +    rc = osLockFileEx(pFile->hFile.h, dwFlags, 0, nByte, 0, &ovlp);
  1840   2356     }
  1841   2357     
  1842   2358     if( rc!= 0 ){
  1843   2359       rc = SQLITE_OK;
  1844   2360     }else{
  1845         -    pFile->lastErrno =  GetLastError();
         2361  +    pFile->lastErrno =  osGetLastError();
  1846   2362       rc = SQLITE_BUSY;
  1847   2363     }
  1848   2364   
  1849   2365     OSTRACE(("SHM-LOCK %d %s %s 0x%08lx\n", 
  1850   2366              pFile->hFile.h,
  1851   2367              rc==SQLITE_OK ? "ok" : "failed",
  1852   2368              lockType==_SHM_UNLCK ? "UnlockFileEx" : "LockFileEx",
................................................................................
  1872   2388     assert( winShmMutexHeld() );
  1873   2389     pp = &winShmNodeList;
  1874   2390     while( (p = *pp)!=0 ){
  1875   2391       if( p->nRef==0 ){
  1876   2392         int i;
  1877   2393         if( p->mutex ) sqlite3_mutex_free(p->mutex);
  1878   2394         for(i=0; i<p->nRegion; i++){
  1879         -        bRc = UnmapViewOfFile(p->aRegion[i].pMap);
         2395  +        bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
  1880   2396           OSTRACE(("SHM-PURGE pid-%d unmap region=%d %s\n",
  1881         -                 (int)GetCurrentProcessId(), i,
         2397  +                 (int)osGetCurrentProcessId(), i,
  1882   2398                    bRc ? "ok" : "failed"));
  1883         -        bRc = CloseHandle(p->aRegion[i].hMap);
         2399  +        bRc = osCloseHandle(p->aRegion[i].hMap);
  1884   2400           OSTRACE(("SHM-PURGE pid-%d close region=%d %s\n",
  1885         -                 (int)GetCurrentProcessId(), i,
         2401  +                 (int)osGetCurrentProcessId(), i,
  1886   2402                    bRc ? "ok" : "failed"));
  1887   2403         }
  1888   2404         if( p->hFile.h != INVALID_HANDLE_VALUE ){
  1889   2405           SimulateIOErrorBenign(1);
  1890   2406           winClose((sqlite3_file *)&p->hFile);
  1891   2407           SimulateIOErrorBenign(0);
  1892   2408         }
................................................................................
  1974   2490   
  1975   2491       /* Check to see if another process is holding the dead-man switch.
  1976   2492       ** If not, truncate the file to zero length. 
  1977   2493       */
  1978   2494       if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){
  1979   2495         rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0);
  1980   2496         if( rc!=SQLITE_OK ){
  1981         -        rc = winLogError(SQLITE_IOERR_SHMOPEN, GetLastError(),
         2497  +        rc = winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(),
  1982   2498                    "winOpenShm", pDbFd->zPath);
  1983   2499         }
  1984   2500       }
  1985   2501       if( rc==SQLITE_OK ){
  1986   2502         winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1);
  1987   2503         rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1);
  1988   2504       }
................................................................................
  2160   2676           assert( (p->sharedMask & mask)==0 );
  2161   2677           p->exclMask |= mask;
  2162   2678         }
  2163   2679       }
  2164   2680     }
  2165   2681     sqlite3_mutex_leave(pShmNode->mutex);
  2166   2682     OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x %s\n",
  2167         -           p->id, (int)GetCurrentProcessId(), p->sharedMask, p->exclMask,
         2683  +           p->id, (int)osGetCurrentProcessId(), p->sharedMask, p->exclMask,
  2168   2684              rc ? "failed" : "ok"));
  2169   2685     return rc;
  2170   2686   }
  2171   2687   
  2172   2688   /*
  2173   2689   ** Implement a memory barrier or memory fence on shared memory.  
  2174   2690   **
................................................................................
  2234   2750   
  2235   2751       /* The requested region is not mapped into this processes address space.
  2236   2752       ** Check to see if it has been allocated (i.e. if the wal-index file is
  2237   2753       ** large enough to contain the requested region).
  2238   2754       */
  2239   2755       rc = winFileSize((sqlite3_file *)&pShmNode->hFile, &sz);
  2240   2756       if( rc!=SQLITE_OK ){
  2241         -      rc = winLogError(SQLITE_IOERR_SHMSIZE, GetLastError(),
         2757  +      rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(),
  2242   2758                  "winShmMap1", pDbFd->zPath);
  2243   2759         goto shmpage_out;
  2244   2760       }
  2245   2761   
  2246   2762       if( sz<nByte ){
  2247   2763         /* The requested memory region does not exist. If isWrite is set to
  2248   2764         ** zero, exit early. *pp will be set to NULL and SQLITE_OK returned.
................................................................................
  2249   2765         **
  2250   2766         ** Alternatively, if isWrite is non-zero, use ftruncate() to allocate
  2251   2767         ** the requested memory region.
  2252   2768         */
  2253   2769         if( !isWrite ) goto shmpage_out;
  2254   2770         rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte);
  2255   2771         if( rc!=SQLITE_OK ){
  2256         -        rc = winLogError(SQLITE_IOERR_SHMSIZE, GetLastError(),
         2772  +        rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(),
  2257   2773                    "winShmMap2", pDbFd->zPath);
  2258   2774           goto shmpage_out;
  2259   2775         }
  2260   2776       }
  2261   2777   
  2262   2778       /* Map the requested memory region into this processes address space. */
  2263   2779       apNew = (struct ShmRegion *)sqlite3_realloc(
................................................................................
  2269   2785       }
  2270   2786       pShmNode->aRegion = apNew;
  2271   2787   
  2272   2788       while( pShmNode->nRegion<=iRegion ){
  2273   2789         HANDLE hMap;                /* file-mapping handle */
  2274   2790         void *pMap = 0;             /* Mapped memory region */
  2275   2791        
  2276         -      hMap = CreateFileMapping(pShmNode->hFile.h, 
         2792  +      hMap = osCreateFileMapping(pShmNode->hFile.h, 
  2277   2793             NULL, PAGE_READWRITE, 0, nByte, NULL
  2278   2794         );
  2279   2795         OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
  2280         -               (int)GetCurrentProcessId(), pShmNode->nRegion, nByte,
         2796  +               (int)osGetCurrentProcessId(), pShmNode->nRegion, nByte,
  2281   2797                  hMap ? "ok" : "failed"));
  2282   2798         if( hMap ){
  2283   2799           int iOffset = pShmNode->nRegion*szRegion;
  2284   2800           int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
  2285         -        pMap = MapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
         2801  +        pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
  2286   2802               0, iOffset - iOffsetShift, szRegion + iOffsetShift
  2287   2803           );
  2288   2804           OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n",
  2289         -                 (int)GetCurrentProcessId(), pShmNode->nRegion, iOffset, szRegion,
  2290         -                 pMap ? "ok" : "failed"));
         2805  +                 (int)osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
         2806  +                 szRegion, pMap ? "ok" : "failed"));
  2291   2807         }
  2292   2808         if( !pMap ){
  2293         -        pShmNode->lastErrno = GetLastError();
         2809  +        pShmNode->lastErrno = osGetLastError();
  2294   2810           rc = winLogError(SQLITE_IOERR_SHMMAP, pShmNode->lastErrno,
  2295   2811                    "winShmMap3", pDbFd->zPath);
  2296         -        if( hMap ) CloseHandle(hMap);
         2812  +        if( hMap ) osCloseHandle(hMap);
  2297   2813           goto shmpage_out;
  2298   2814         }
  2299   2815   
  2300   2816         pShmNode->aRegion[pShmNode->nRegion].pMap = pMap;
  2301   2817         pShmNode->aRegion[pShmNode->nRegion].hMap = hMap;
  2302   2818         pShmNode->nRegion++;
  2303   2819       }
................................................................................
  2400   2916     SimulateIOError( return SQLITE_IOERR );
  2401   2917   
  2402   2918     if( sqlite3_temp_directory ){
  2403   2919       sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
  2404   2920     }else if( isNT() ){
  2405   2921       char *zMulti;
  2406   2922       WCHAR zWidePath[MAX_PATH];
  2407         -    GetTempPathW(MAX_PATH-30, zWidePath);
         2923  +    osGetTempPathW(MAX_PATH-30, zWidePath);
  2408   2924       zMulti = unicodeToUtf8(zWidePath);
  2409   2925       if( zMulti ){
  2410   2926         sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti);
  2411   2927         free(zMulti);
  2412   2928       }else{
  2413   2929         return SQLITE_NOMEM;
  2414   2930       }
................................................................................
  2416   2932   ** Since the ASCII version of these Windows API do not exist for WINCE,
  2417   2933   ** it's important to not reference them for WINCE builds.
  2418   2934   */
  2419   2935   #if SQLITE_OS_WINCE==0
  2420   2936     }else{
  2421   2937       char *zUtf8;
  2422   2938       char zMbcsPath[MAX_PATH];
  2423         -    GetTempPathA(MAX_PATH-30, zMbcsPath);
         2939  +    osGetTempPathA(MAX_PATH-30, zMbcsPath);
  2424   2940       zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
  2425   2941       if( zUtf8 ){
  2426   2942         sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8);
  2427   2943         free(zUtf8);
  2428   2944       }else{
  2429   2945         return SQLITE_NOMEM;
  2430   2946       }
................................................................................
  2591   3107     /* Reports from the internet are that performance is always
  2592   3108     ** better if FILE_FLAG_RANDOM_ACCESS is used.  Ticket #2699. */
  2593   3109   #if SQLITE_OS_WINCE
  2594   3110     dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
  2595   3111   #endif
  2596   3112   
  2597   3113     if( isNT() ){
  2598         -    while( (h = CreateFileW((WCHAR*)zConverted,
  2599         -                            dwDesiredAccess,
  2600         -                            dwShareMode, NULL,
  2601         -                            dwCreationDisposition,
  2602         -                            dwFlagsAndAttributes,
  2603         -                            NULL))==INVALID_HANDLE_VALUE &&
  2604         -                            retryIoerr(&cnt) ){}
         3114  +    while( (h = osCreateFileW((LPCWSTR)zConverted,
         3115  +                              dwDesiredAccess,
         3116  +                              dwShareMode, NULL,
         3117  +                              dwCreationDisposition,
         3118  +                              dwFlagsAndAttributes,
         3119  +                              NULL))==INVALID_HANDLE_VALUE &&
         3120  +                              retryIoerr(&cnt) ){}
  2605   3121   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  2606   3122   ** Since the ASCII version of these Windows API do not exist for WINCE,
  2607   3123   ** it's important to not reference them for WINCE builds.
  2608   3124   */
  2609   3125   #if SQLITE_OS_WINCE==0
  2610   3126     }else{
  2611         -    while( (h = CreateFileA((char*)zConverted,
  2612         -                            dwDesiredAccess,
  2613         -                            dwShareMode, NULL,
  2614         -                            dwCreationDisposition,
  2615         -                            dwFlagsAndAttributes,
  2616         -                            NULL))==INVALID_HANDLE_VALUE &&
  2617         -                            retryIoerr(&cnt) ){}
         3127  +    while( (h = osCreateFileA((LPCSTR)zConverted,
         3128  +                              dwDesiredAccess,
         3129  +                              dwShareMode, NULL,
         3130  +                              dwCreationDisposition,
         3131  +                              dwFlagsAndAttributes,
         3132  +                              NULL))==INVALID_HANDLE_VALUE &&
         3133  +                              retryIoerr(&cnt) ){}
  2618   3134   #endif
  2619   3135     }
  2620   3136   
  2621   3137     logIoerr(cnt);
  2622   3138   
  2623   3139     OSTRACE(("OPEN %d %s 0x%lx %s\n", 
  2624   3140              h, zName, dwDesiredAccess, 
  2625   3141              h==INVALID_HANDLE_VALUE ? "failed" : "ok"));
  2626   3142   
  2627   3143     if( h==INVALID_HANDLE_VALUE ){
  2628         -    pFile->lastErrno = GetLastError();
         3144  +    pFile->lastErrno = osGetLastError();
  2629   3145       winLogError(SQLITE_CANTOPEN, pFile->lastErrno, "winOpen", zUtf8Name);
  2630   3146       free(zConverted);
  2631   3147       if( isReadWrite && !isExclusive ){
  2632   3148         return winOpen(pVfs, zName, id, 
  2633   3149                ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags);
  2634   3150       }else{
  2635   3151         return SQLITE_CANTOPEN_BKPT;
................................................................................
  2653   3169     pFile->zPath = zName;
  2654   3170     pFile->sectorSize = getSectorSize(pVfs, zUtf8Name);
  2655   3171   
  2656   3172   #if SQLITE_OS_WINCE
  2657   3173     if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
  2658   3174          && !winceCreateLock(zName, pFile)
  2659   3175     ){
  2660         -    CloseHandle(h);
         3176  +    osCloseHandle(h);
  2661   3177       free(zConverted);
  2662   3178       return SQLITE_CANTOPEN_BKPT;
  2663   3179     }
  2664   3180     if( isTemp ){
  2665   3181       pFile->zDeleteOnClose = zConverted;
  2666   3182     }else
  2667   3183   #endif
................................................................................
  2672   3188     OpenCounter(+1);
  2673   3189     return rc;
  2674   3190   }
  2675   3191   
  2676   3192   /*
  2677   3193   ** Delete the named file.
  2678   3194   **
  2679         -** Note that windows does not allow a file to be deleted if some other
         3195  +** Note that Windows does not allow a file to be deleted if some other
  2680   3196   ** process has it open.  Sometimes a virus scanner or indexing program
  2681   3197   ** will open a journal file shortly after it is created in order to do
  2682   3198   ** whatever it does.  While this other process is holding the
  2683   3199   ** file open, we will be unable to delete it.  To work around this
  2684   3200   ** problem, we delay 100 milliseconds and try to delete again.  Up
  2685   3201   ** to MX_DELETION_ATTEMPTs deletion attempts are run before giving
  2686   3202   ** up and returning an error.
................................................................................
  2699   3215     SimulateIOError(return SQLITE_IOERR_DELETE);
  2700   3216     zConverted = convertUtf8Filename(zFilename);
  2701   3217     if( zConverted==0 ){
  2702   3218       return SQLITE_NOMEM;
  2703   3219     }
  2704   3220     if( isNT() ){
  2705   3221       rc = 1;
  2706         -    while( GetFileAttributesW(zConverted)!=INVALID_FILE_ATTRIBUTES &&
  2707         -           (rc = DeleteFileW(zConverted))==0 && retryIoerr(&cnt) ){}
         3222  +    while( osGetFileAttributesW(zConverted)!=INVALID_FILE_ATTRIBUTES &&
         3223  +           (rc = osDeleteFileW(zConverted))==0 && retryIoerr(&cnt) ){}
  2708   3224       rc = rc ? SQLITE_OK : SQLITE_ERROR;
  2709   3225   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  2710   3226   ** Since the ASCII version of these Windows API do not exist for WINCE,
  2711   3227   ** it's important to not reference them for WINCE builds.
  2712   3228   */
  2713   3229   #if SQLITE_OS_WINCE==0
  2714   3230     }else{
  2715   3231       rc = 1;
  2716         -    while( GetFileAttributesA(zConverted)!=INVALID_FILE_ATTRIBUTES &&
  2717         -           (rc = DeleteFileA(zConverted))==0 && retryIoerr(&cnt) ){}
         3232  +    while( osGetFileAttributesA(zConverted)!=INVALID_FILE_ATTRIBUTES &&
         3233  +           (rc = osDeleteFileA(zConverted))==0 && retryIoerr(&cnt) ){}
  2718   3234       rc = rc ? SQLITE_OK : SQLITE_ERROR;
  2719   3235   #endif
  2720   3236     }
  2721   3237     if( rc ){
  2722         -    rc = winLogError(SQLITE_IOERR_DELETE, GetLastError(),
         3238  +    rc = winLogError(SQLITE_IOERR_DELETE, osGetLastError(),
  2723   3239                "winDelete", zFilename);
  2724   3240     }else{
  2725   3241       logIoerr(cnt);
  2726   3242     }
  2727   3243     free(zConverted);
  2728   3244     OSTRACE(("DELETE \"%s\" %s\n", zFilename, (rc ? "failed" : "ok" )));
  2729   3245     return rc;
................................................................................
  2748   3264     if( zConverted==0 ){
  2749   3265       return SQLITE_NOMEM;
  2750   3266     }
  2751   3267     if( isNT() ){
  2752   3268       int cnt = 0;
  2753   3269       WIN32_FILE_ATTRIBUTE_DATA sAttrData;
  2754   3270       memset(&sAttrData, 0, sizeof(sAttrData));
  2755         -    while( !(rc = GetFileAttributesExW((WCHAR*)zConverted,
         3271  +    while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
  2756   3272                                GetFileExInfoStandard, 
  2757   3273                                &sAttrData)) && retryIoerr(&cnt) ){}
  2758   3274       if( rc ){
  2759   3275         /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
  2760   3276         ** as if it does not exist.
  2761   3277         */
  2762   3278         if(    flags==SQLITE_ACCESS_EXISTS
................................................................................
  2763   3279             && sAttrData.nFileSizeHigh==0 
  2764   3280             && sAttrData.nFileSizeLow==0 ){
  2765   3281           attr = INVALID_FILE_ATTRIBUTES;
  2766   3282         }else{
  2767   3283           attr = sAttrData.dwFileAttributes;
  2768   3284         }
  2769   3285       }else{
  2770         -      DWORD lastErrno = GetLastError();
         3286  +      DWORD lastErrno = osGetLastError();
  2771   3287         logIoerr(cnt);
  2772   3288         if( lastErrno!=ERROR_FILE_NOT_FOUND ){
  2773   3289           winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", zFilename);
  2774   3290           free(zConverted);
  2775   3291           return SQLITE_IOERR_ACCESS;
  2776   3292         }else{
  2777   3293           attr = INVALID_FILE_ATTRIBUTES;
................................................................................
  2779   3295       }
  2780   3296   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  2781   3297   ** Since the ASCII version of these Windows API do not exist for WINCE,
  2782   3298   ** it's important to not reference them for WINCE builds.
  2783   3299   */
  2784   3300   #if SQLITE_OS_WINCE==0
  2785   3301     }else{
  2786         -    attr = GetFileAttributesA((char*)zConverted);
         3302  +    attr = osGetFileAttributesA((char*)zConverted);
  2787   3303   #endif
  2788   3304     }
  2789   3305     free(zConverted);
  2790   3306     switch( flags ){
  2791   3307       case SQLITE_ACCESS_READ:
  2792   3308       case SQLITE_ACCESS_EXISTS:
  2793   3309         rc = attr!=INVALID_FILE_ATTRIBUTES;
................................................................................
  2848   3364     ** function failing. This function could fail if, for example, the
  2849   3365     ** current working directory has been unlinked.
  2850   3366     */
  2851   3367     SimulateIOError( return SQLITE_ERROR );
  2852   3368     UNUSED_PARAMETER(nFull);
  2853   3369     zConverted = convertUtf8Filename(zRelative);
  2854   3370     if( isNT() ){
  2855         -    WCHAR *zTemp;
  2856         -    nByte = GetFullPathNameW((WCHAR*)zConverted, 0, 0, 0) + 3;
         3371  +    LPWSTR zTemp;
         3372  +    nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0) + 3;
  2857   3373       zTemp = malloc( nByte*sizeof(zTemp[0]) );
  2858   3374       if( zTemp==0 ){
  2859   3375         free(zConverted);
  2860   3376         return SQLITE_NOMEM;
  2861   3377       }
  2862         -    GetFullPathNameW((WCHAR*)zConverted, nByte, zTemp, 0);
         3378  +    osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
  2863   3379       free(zConverted);
  2864   3380       zOut = unicodeToUtf8(zTemp);
  2865   3381       free(zTemp);
  2866   3382   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  2867   3383   ** Since the ASCII version of these Windows API do not exist for WINCE,
  2868   3384   ** it's important to not reference them for WINCE builds.
  2869   3385   */
  2870   3386   #if SQLITE_OS_WINCE==0
  2871   3387     }else{
  2872   3388       char *zTemp;
  2873         -    nByte = GetFullPathNameA((char*)zConverted, 0, 0, 0) + 3;
         3389  +    nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0) + 3;
  2874   3390       zTemp = malloc( nByte*sizeof(zTemp[0]) );
  2875   3391       if( zTemp==0 ){
  2876   3392         free(zConverted);
  2877   3393         return SQLITE_NOMEM;
  2878   3394       }
  2879         -    GetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
         3395  +    osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
  2880   3396       free(zConverted);
  2881   3397       zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
  2882   3398       free(zTemp);
  2883   3399   #endif
  2884   3400     }
  2885   3401     if( zOut ){
  2886   3402       sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zOut);
................................................................................
  2921   3437     SimulateIOErrorBenign(0);
  2922   3438     if( rc == SQLITE_OK )
  2923   3439     {
  2924   3440       void *zConverted = convertUtf8Filename(zFullpath);
  2925   3441       if( zConverted ){
  2926   3442         if( isNT() ){
  2927   3443           /* trim path to just drive reference */
  2928         -        WCHAR *p = zConverted;
         3444  +        LPWSTR p = zConverted;
  2929   3445           for(;*p;p++){
  2930   3446             if( *p == '\\' ){
  2931   3447               *p = '\0';
  2932   3448               break;
  2933   3449             }
  2934   3450           }
  2935         -        dwRet = GetDiskFreeSpaceW((WCHAR*)zConverted,
  2936         -                                  &dwDummy,
  2937         -                                  &bytesPerSector,
  2938         -                                  &dwDummy,
  2939         -                                  &dwDummy);
         3451  +        dwRet = osGetDiskFreeSpaceW((LPCWSTR)zConverted,
         3452  +                                    &dwDummy,
         3453  +                                    &bytesPerSector,
         3454  +                                    &dwDummy,
         3455  +                                    &dwDummy);
  2940   3456         }else{
  2941   3457           /* trim path to just drive reference */
  2942   3458           char *p = (char *)zConverted;
  2943   3459           for(;*p;p++){
  2944   3460             if( *p == '\\' ){
  2945   3461               *p = '\0';
  2946   3462               break;
  2947   3463             }
  2948   3464           }
  2949         -        dwRet = GetDiskFreeSpaceA((char*)zConverted,
  2950         -                                  &dwDummy,
  2951         -                                  &bytesPerSector,
  2952         -                                  &dwDummy,
  2953         -                                  &dwDummy);
         3465  +        dwRet = osGetDiskFreeSpaceA((char*)zConverted,
         3466  +                                    &dwDummy,
         3467  +                                    &bytesPerSector,
         3468  +                                    &dwDummy,
         3469  +                                    &dwDummy);
  2954   3470         }
  2955   3471         free(zConverted);
  2956   3472       }
  2957   3473       if( !dwRet ){
  2958   3474         bytesPerSector = SQLITE_DEFAULT_SECTOR_SIZE;
  2959   3475       }
  2960   3476     }
................................................................................
  2975   3491     HANDLE h;
  2976   3492     void *zConverted = convertUtf8Filename(zFilename);
  2977   3493     UNUSED_PARAMETER(pVfs);
  2978   3494     if( zConverted==0 ){
  2979   3495       return 0;
  2980   3496     }
  2981   3497     if( isNT() ){
  2982         -    h = LoadLibraryW((WCHAR*)zConverted);
         3498  +    h = osLoadLibraryW((LPCWSTR)zConverted);
  2983   3499   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  2984   3500   ** Since the ASCII version of these Windows API do not exist for WINCE,
  2985   3501   ** it's important to not reference them for WINCE builds.
  2986   3502   */
  2987   3503   #if SQLITE_OS_WINCE==0
  2988   3504     }else{
  2989         -    h = LoadLibraryA((char*)zConverted);
         3505  +    h = osLoadLibraryA((char*)zConverted);
  2990   3506   #endif
  2991   3507     }
  2992   3508     free(zConverted);
  2993   3509     return (void*)h;
  2994   3510   }
  2995   3511   static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
  2996   3512     UNUSED_PARAMETER(pVfs);
  2997         -  getLastErrorMsg(GetLastError(), nBuf, zBufOut);
         3513  +  getLastErrorMsg(osGetLastError(), nBuf, zBufOut);
  2998   3514   }
  2999   3515   static void (*winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(void){
  3000   3516     UNUSED_PARAMETER(pVfs);
  3001         -#if SQLITE_OS_WINCE
  3002         -  /* The GetProcAddressA() routine is only available on wince. */
  3003         -  return (void(*)(void))GetProcAddressA((HANDLE)pHandle, zSymbol);
  3004         -#else
  3005         -  /* All other windows platforms expect GetProcAddress() to take
  3006         -  ** an Ansi string regardless of the _UNICODE setting */
  3007         -  return (void(*)(void))GetProcAddress((HANDLE)pHandle, zSymbol);
  3008         -#endif
         3517  +  return (void(*)(void))osGetProcAddressA((HANDLE)pHandle, zSymbol);
  3009   3518   }
  3010   3519   static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
  3011   3520     UNUSED_PARAMETER(pVfs);
  3012         -  FreeLibrary((HANDLE)pHandle);
         3521  +  osFreeLibrary((HANDLE)pHandle);
  3013   3522   }
  3014   3523   #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
  3015   3524     #define winDlOpen  0
  3016   3525     #define winDlError 0
  3017   3526     #define winDlSym   0
  3018   3527     #define winDlClose 0
  3019   3528   #endif
................................................................................
  3027   3536     UNUSED_PARAMETER(pVfs);
  3028   3537   #if defined(SQLITE_TEST)
  3029   3538     n = nBuf;
  3030   3539     memset(zBuf, 0, nBuf);
  3031   3540   #else
  3032   3541     if( sizeof(SYSTEMTIME)<=nBuf-n ){
  3033   3542       SYSTEMTIME x;
  3034         -    GetSystemTime(&x);
         3543  +    osGetSystemTime(&x);
  3035   3544       memcpy(&zBuf[n], &x, sizeof(x));
  3036   3545       n += sizeof(x);
  3037   3546     }
  3038   3547     if( sizeof(DWORD)<=nBuf-n ){
  3039         -    DWORD pid = GetCurrentProcessId();
         3548  +    DWORD pid = osGetCurrentProcessId();
  3040   3549       memcpy(&zBuf[n], &pid, sizeof(pid));
  3041   3550       n += sizeof(pid);
  3042   3551     }
  3043   3552     if( sizeof(DWORD)<=nBuf-n ){
  3044         -    DWORD cnt = GetTickCount();
         3553  +    DWORD cnt = osGetTickCount();
  3045   3554       memcpy(&zBuf[n], &cnt, sizeof(cnt));
  3046   3555       n += sizeof(cnt);
  3047   3556     }
  3048   3557     if( sizeof(LARGE_INTEGER)<=nBuf-n ){
  3049   3558       LARGE_INTEGER i;
  3050         -    QueryPerformanceCounter(&i);
         3559  +    osQueryPerformanceCounter(&i);
  3051   3560       memcpy(&zBuf[n], &i, sizeof(i));
  3052   3561       n += sizeof(i);
  3053   3562     }
  3054   3563   #endif
  3055   3564     return n;
  3056   3565   }
  3057   3566   
  3058   3567   
  3059   3568   /*
  3060   3569   ** Sleep for a little while.  Return the amount of time slept.
  3061   3570   */
  3062   3571   static int winSleep(sqlite3_vfs *pVfs, int microsec){
  3063         -  Sleep((microsec+999)/1000);
         3572  +  osSleep((microsec+999)/1000);
  3064   3573     UNUSED_PARAMETER(pVfs);
  3065   3574     return ((microsec+999)/1000)*1000;
  3066   3575   }
  3067   3576   
  3068   3577   /*
  3069   3578   ** The following variable, if set to a non-zero value, is interpreted as
  3070   3579   ** the number of seconds since 1970 and is used to set the result of
................................................................................
  3095   3604   #endif
  3096   3605     /* 2^32 - to avoid use of LL and warnings in gcc */
  3097   3606     static const sqlite3_int64 max32BitValue = 
  3098   3607         (sqlite3_int64)2000000000 + (sqlite3_int64)2000000000 + (sqlite3_int64)294967296;
  3099   3608   
  3100   3609   #if SQLITE_OS_WINCE
  3101   3610     SYSTEMTIME time;
  3102         -  GetSystemTime(&time);
         3611  +  osGetSystemTime(&time);
  3103   3612     /* if SystemTimeToFileTime() fails, it returns zero. */
  3104         -  if (!SystemTimeToFileTime(&time,&ft)){
         3613  +  if (!osSystemTimeToFileTime(&time,&ft)){
  3105   3614       return SQLITE_ERROR;
  3106   3615     }
  3107   3616   #else
  3108         -  GetSystemTimeAsFileTime( &ft );
         3617  +  osGetSystemTimeAsFileTime( &ft );
  3109   3618   #endif
  3110   3619   
  3111   3620     *piNow = winFiletimeEpoch +
  3112   3621               ((((sqlite3_int64)ft.dwHighDateTime)*max32BitValue) + 
  3113   3622                  (sqlite3_int64)ft.dwLowDateTime)/(sqlite3_int64)10000;
  3114   3623   
  3115   3624   #ifdef SQLITE_TEST
................................................................................
  3134   3643       *prNow = i/86400000.0;
  3135   3644     }
  3136   3645     return rc;
  3137   3646   }
  3138   3647   
  3139   3648   /*
  3140   3649   ** The idea is that this function works like a combination of
  3141         -** GetLastError() and FormatMessage() on windows (or errno and
  3142         -** strerror_r() on unix). After an error is returned by an OS
         3650  +** GetLastError() and FormatMessage() on Windows (or errno and
         3651  +** strerror_r() on Unix). After an error is returned by an OS
  3143   3652   ** function, SQLite calls this function with zBuf pointing to
  3144   3653   ** a buffer of nBuf bytes. The OS layer should populate the
  3145   3654   ** buffer with a nul-terminated UTF-8 encoded error message
  3146   3655   ** describing the last IO error to have occurred within the calling
  3147   3656   ** thread.
  3148   3657   **
  3149   3658   ** If the error message is too large for the supplied buffer,
................................................................................
  3164   3673   **
  3165   3674   ** However if an error message is supplied, it will be incorporated
  3166   3675   ** by sqlite into the error message available to the user using
  3167   3676   ** sqlite3_errmsg(), possibly making IO errors easier to debug.
  3168   3677   */
  3169   3678   static int winGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
  3170   3679     UNUSED_PARAMETER(pVfs);
  3171         -  return getLastErrorMsg(GetLastError(), nBuf, zBuf);
         3680  +  return getLastErrorMsg(osGetLastError(), nBuf, zBuf);
  3172   3681   }
  3173   3682   
  3174   3683   
  3175   3684   
  3176   3685   /*
  3177   3686   ** Initialize and deinitialize the operating system interface.
  3178   3687   */
................................................................................
  3193   3702       winDlSym,            /* xDlSym */
  3194   3703       winDlClose,          /* xDlClose */
  3195   3704       winRandomness,       /* xRandomness */
  3196   3705       winSleep,            /* xSleep */
  3197   3706       winCurrentTime,      /* xCurrentTime */
  3198   3707       winGetLastError,     /* xGetLastError */
  3199   3708       winCurrentTimeInt64, /* xCurrentTimeInt64 */
  3200         -    0,                   /* xSetSystemCall */
  3201         -    0,                   /* xGetSystemCall */
  3202         -    0,                   /* xNextSystemCall */
         3709  +    winSetSystemCall,    /* xSetSystemCall */
         3710  +    winGetSystemCall,    /* xGetSystemCall */
         3711  +    winNextSystemCall,   /* xNextSystemCall */
  3203   3712     };
         3713  +
         3714  +  /* Double-check that the aSyscall[] array has been constructed
         3715  +  ** correctly.  See ticket [bb3a86e890c8e96ab] */
         3716  +  assert( ArraySize(aSyscall)==60 );
  3204   3717   
  3205   3718   #ifndef SQLITE_OMIT_WAL
  3206   3719     /* get memory map allocation granularity */
  3207   3720     memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
  3208         -  GetSystemInfo(&winSysInfo);
         3721  +  osGetSystemInfo(&winSysInfo);
  3209   3722     assert(winSysInfo.dwAllocationGranularity > 0);
  3210   3723   #endif
  3211   3724   
  3212   3725     sqlite3_vfs_register(&winVfs, 1);
  3213   3726     return SQLITE_OK; 
  3214   3727   }
  3215   3728   int sqlite3_os_end(void){ 
  3216   3729     return SQLITE_OK;
  3217   3730   }
  3218   3731   
  3219   3732   #endif /* SQLITE_OS_WIN */