From 2593b8791101b17b63182c3ac3f686529f0dcf6f Mon Sep 17 00:00:00 2001 From: Alexpux Date: Tue, 17 Dec 2013 14:05:07 +0400 Subject: [PATCH] sqlite: Update to 3.8.2 --- sqlite/PKGBUILD | 30 +- sqlite/sqlite3-3.8.1-1.src.patch | 770 ------------ sqlite/sqlite3-3.8.2-2.src.patch | 1887 ++++++++++++++++++++++++++++++ 3 files changed, 1905 insertions(+), 782 deletions(-) delete mode 100644 sqlite/sqlite3-3.8.1-1.src.patch create mode 100644 sqlite/sqlite3-3.8.2-2.src.patch diff --git a/sqlite/PKGBUILD b/sqlite/PKGBUILD index fc9748e9..e9a6a55c 100644 --- a/sqlite/PKGBUILD +++ b/sqlite/PKGBUILD @@ -2,11 +2,11 @@ pkgbase="sqlite" pkgname=('sqlite' 'libsqlite' 'libsqlite-devel' 'sqlite-doc') -_amalgamationver=3080100 +_amalgamationver=3080200 _docver=${_amalgamationver} #_docver=3080001 -pkgver=3.8.1 -pkgrel=3 +pkgver=3.8.2 +pkgrel=1 pkgdesc="A C library that implements an SQL database engine" arch=('i686' 'x86_64') license=('custom:Public Domain') @@ -18,19 +18,19 @@ source=( # tarball containing the amalgamation for SQLite >= 3.7.5 together with http://www.sqlite.org/2013/sqlite-doc-${_docver}.zip license.txt 'sqlite-3.8.0.1-msys2.patch' - 'sqlite3-3.8.1-1.src.patch') + 'sqlite3-3.8.2-2.src.patch') options=('!libtool' '!emptydirs') -sha1sums=('42464b07df2d6f8aa28f73ce4cc6d48b47be810e' - 'd7cb698f32318fbf5dce9f10c9cd7b84c3d70105' +sha1sums=('6033ef603ce221d367c665477514d972ef1dc90e' + 'b9cbd42d08b8c1ce96656a6b111e918bb515b605' 'f34f6daa4ab3073d74e774aad21d66878cf26853' '0810721cc17128498f99863c185753e06a95ad79' - '24c8852974b13953988e49a6101f923e6cacd92b') + '2379775ffa7488b187cac3ff3094e2cc298a9357') prepare() { cd "$srcdir"/sqlite-autoconf-$_amalgamationver patch -p1 -i ${srcdir}/sqlite-3.8.0.1-msys2.patch - patch -p2 -i ${srcdir}/sqlite3-3.8.1-1.src.patch + patch -p2 -i ${srcdir}/sqlite3-3.8.2-2.src.patch autoreconf -fi } @@ -38,13 +38,20 @@ build() { export CPPFLAGS="$CPPFLAGS \ -DHAVE_MALLOC_H \ -DHAVE_MALLOC_USABLE_SIZE \ - -DSQLITE_OS_UNIX=1 \ - -DSQLITE_OS_WIN=1 \ + -DSQLITE_DEFAULT_FILE_FORMAT=4 \ -DSQLITE_ENABLE_COLUMN_METADATA=1 \ + -DSQLITE_ENABLE_EXPLAIN_COMMENTS=1 \ -DSQLITE_ENABLE_FTS3=1 \ -DSQLITE_ENABLE_FTS4=1 \ -DSQLITE_ENABLE_LOCKING_STYLE=1 \ - -DSQLITE_ENABLE_RTREE=1" + -DSQLITE_ENABLE_RTREE=1 \ + -DSQLITE_ENABLE_STAT4=1 \ + -DSQLITE_ENABLE_UNLOCK_NOTIFY=1 \ + -DSQLITE_OS_UNIX=1 \ + -DSQLITE_OS_WIN=1 \ + -DSQLITE_SOUNDEX=1 \ + -DSQLITE_WIN32_NO_ANSI=1 \ + -DSQLITE_WINNT_MAX_PATH_CHARS=4096" # build sqlite cd "$srcdir"/sqlite-autoconf-$_amalgamationver @@ -68,7 +75,6 @@ package_sqlite() { depends=('libreadline' 'libsqlite') provides=("sqlite3=$pkgver") replaces=("sqlite3") - groups=('base-devel') mkdir -p ${pkgdir}/usr/bin cp -f ${srcdir}/dest/usr/bin/*.exe ${pkgdir}/usr/bin/ diff --git a/sqlite/sqlite3-3.8.1-1.src.patch b/sqlite/sqlite3-3.8.1-1.src.patch deleted file mode 100644 index e98742d2..00000000 --- a/sqlite/sqlite3-3.8.1-1.src.patch +++ /dev/null @@ -1,770 +0,0 @@ ---- origsrc/sqlite-autoconf-3080100/sqlite3.c 2013-10-17 15:57:34.000000000 +0200 -+++ src/sqlite-autoconf-3080100/sqlite3.c 2013-11-13 14:30:38.528187400 +0100 -@@ -9669,7 +9669,10 @@ SQLITE_PRIVATE void sqlite3PCacheSetDefa - #if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER) - # define SQLITE_OS_OTHER 0 - # ifndef SQLITE_OS_WIN --# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__) -+# if defined(__CYGWIN__) -+# define SQLITE_OS_WIN 1 -+# define SQLITE_OS_UNIX 1 -+# elif defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || defined(__BORLANDC__) - # define SQLITE_OS_WIN 1 - # define SQLITE_OS_UNIX 0 - # else -@@ -9685,7 +9688,7 @@ SQLITE_PRIVATE void sqlite3PCacheSetDefa - # endif - #endif - --#if SQLITE_OS_WIN -+#if SQLITE_OS_WIN && !defined(__CYGWIN__) - # include - #endif - -@@ -9957,10 +9960,10 @@ SQLITE_PRIVATE int sqlite3OsCloseFree(sq - # define SQLITE_MUTEX_OMIT - #endif - #if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP) --# if SQLITE_OS_UNIX --# define SQLITE_MUTEX_PTHREADS --# elif SQLITE_OS_WIN -+# if SQLITE_OS_WIN - # define SQLITE_MUTEX_W32 -+# elif SQLITE_OS_UNIX -+# define SQLITE_MUTEX_PTHREADS - # else - # define SQLITE_MUTEX_NOOP - # endif -@@ -18485,6 +18488,10 @@ SQLITE_PRIVATE sqlite3_mutex_methods con - ** This file contains the C functions that implement mutexes for win32 - */ - -+#ifdef __CYGWIN__ -+# include /* amalgamator: keep */ -+#endif -+ - /* - ** The code in this file is only used if we are compiling multithreaded - ** on a win32 system. -@@ -23007,21 +23014,23 @@ SQLITE_PRIVATE const char *sqlite3Opcode - ** There are various methods for file locking used for concurrency - ** control: - ** --** 1. POSIX locking (the default), -+** 1. POSIX locking (the default, except on Cygwin), - ** 2. No locking, - ** 3. Dot-file locking, - ** 4. flock() locking, - ** 5. AFP locking (OSX only), - ** 6. Named POSIX semaphores (VXWorks only), - ** 7. proxy locking. (OSX only) -+** 8. winnt locking. (Cygwin only, default on Cygwin) - ** - ** Styles 4, 5, and 7 are only available of SQLITE_ENABLE_LOCKING_STYLE - ** is defined to 1. The SQLITE_ENABLE_LOCKING_STYLE also enables automatic - ** selection of the appropriate locking style based on the filesystem --** where the database is located. -+** where the database is located. On Cygwin, flock() locking is always -+** available, but winnt locking is the default. - */ - #if !defined(SQLITE_ENABLE_LOCKING_STYLE) --# if defined(__APPLE__) -+# if defined(__APPLE__) || defined(__CYGWIN__) - # define SQLITE_ENABLE_LOCKING_STYLE 1 - # else - # define SQLITE_ENABLE_LOCKING_STYLE 0 -@@ -23080,8 +23089,11 @@ SQLITE_PRIVATE const char *sqlite3Opcode - #include - #endif - -+#ifdef __CYGWIN__ -+# include -+#endif - --#if SQLITE_ENABLE_LOCKING_STYLE -+#if SQLITE_ENABLE_LOCKING_STYLE || defined(__CYGWIN__) - # include - # if OS_VXWORKS - # include -@@ -23186,10 +23198,10 @@ struct unixFile { - int sectorSize; /* Device sector size */ - int deviceCharacteristics; /* Precomputed device characteristics */ - #endif --#if SQLITE_ENABLE_LOCKING_STYLE -+#if SQLITE_ENABLE_LOCKING_STYLE && !defined(__CYGWIN__) - int openFlags; /* The flags specified at open() */ - #endif --#if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__) -+#if SQLITE_ENABLE_LOCKING_STYLE && !defined(__CYGWIN__) || defined(__APPLE__) - unsigned fsFlags; /* cached details from statfs() */ - #endif - #if OS_VXWORKS -@@ -23515,6 +23527,9 @@ static int openDirectory(const char*, in - ** testing and sandboxing. The following array holds the names and pointers - ** to all overrideable system calls. - */ -+#if SQLITE_OS_WIN -+# define aSyscall aUnixSyscall -+#endif - static struct unix_syscall { - const char *zName; /* Name of the system call */ - sqlite3_syscall_ptr pCurrent; /* Current value of the system call */ -@@ -25381,9 +25396,9 @@ static int dotlockClose(sqlite3_file *id - ** only a single process can be reading the database at a time. - ** - ** Omit this section if SQLITE_ENABLE_LOCKING_STYLE is turned off or if --** compiling for VXWORKS. -+** compiling for VXWORKS, except on Cygwin. - */ --#if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS -+#if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS || defined(__CYGWIN__) - - /* - ** Retry flock() calls that fail with EINTR -@@ -26528,8 +26543,7 @@ static int unixWrite( - ** Count the number of fullsyncs and normal syncs. This is used to test - ** that syncs and fullsyncs are occurring at the right times. - */ --SQLITE_API int sqlite3_sync_count = 0; --SQLITE_API int sqlite3_fullsync_count = 0; -+extern int sqlite3_sync_count, sqlite3_fullsync_count; - #endif - - /* -@@ -28120,7 +28134,19 @@ IOMETHODS( - dotlockCheckReservedLock /* xCheckReservedLock method */ - ) - --#if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS -+#if defined(__CYGWIN__) -+IOMETHODS( -+ winntIoFinder, /* Finder function name */ -+ winntIoMethods, /* sqlite3_io_methods object name */ -+ 1, /* shared memory is disabled */ -+ flockClose, /* xClose method */ -+ flockLock, /* xLock method */ -+ flockUnlock, /* xUnlock method */ -+ flockCheckReservedLock /* xCheckReservedLock method */ -+) -+#endif -+ -+#if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS || defined(__CYGWIN__) - IOMETHODS( - flockIoFinder, /* Finder function name */ - flockIoMethods, /* sqlite3_io_methods object name */ -@@ -28298,6 +28324,46 @@ static const sqlite3_io_methods - - #endif /* OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE */ - -+#if defined(__CYGWIN__) && SQLITE_ENABLE_LOCKING_STYLE -+/* -+** This "finder" function attempts to determine the best locking strategy -+** for the database file "filePath". It then returns the sqlite3_io_methods -+** object that implements that strategy. -+** -+** This is for Cygwin only. -+*/ -+static const sqlite3_io_methods *autolockIoFinderImpl( -+ const char *filePath, /* name of the database file */ -+ unixFile *pNew /* the open file object */ -+){ -+ static const sqlite3_io_methods *ioMethods = NULL; -+ -+ if( !filePath ){ -+ /* If filePath==NULL that means we are dealing with a transient file -+ ** that does not need to be locked. */ -+ return &nolockIoMethods; -+ } -+ -+ if( !ioMethods ){ -+ const char *strategy = getenv("CYGWIN_SQLITE_LOCKING"); -+ ioMethods = &winntIoMethods; -+ if( strategy ){ -+ if( sqlite3_stricmp(strategy, "posix") == 0 ){ -+ ioMethods = &posixIoMethods; -+ }else if( sqlite3_stricmp(strategy, "bsd") == 0 ){ -+ ioMethods = &flockIoMethods; -+ }else if( sqlite3_stricmp(strategy, "dotfile") == 0 ){ -+ ioMethods = &dotlockIoMethods; -+ } -+ } -+ } -+ return ioMethods; -+} -+static const sqlite3_io_methods -+ *(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl; -+ -+#endif /* OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE */ -+ - /* - ** An abstract type for a pointer to a IO method finder function: - */ -@@ -28477,7 +28543,16 @@ static int fillInUnixFile( - unixLeaveMutex(); - } - #endif -- -+ -+#if defined(__CYGWIN__) -+ else if( pLockingStyle == &winntIoMethods ){ -+ if ((osFcntl(h, F_LCK_MANDATORY, 1) != 0) && (errno != EINVAL)) { -+ /* The API exists but it refused to enable mandatory locking! */ -+ rc = SQLITE_IOERR_ACCESS; -+ } -+ } -+#endif -+ - pNew->lastErrno = 0; - #if OS_VXWORKS - if( rc!=SQLITE_OK ){ -@@ -28506,6 +28581,8 @@ static const char *unixTempFileDir(void) - 0, - 0, - 0, -+ 0, -+ 0, - "/var/tmp", - "/usr/tmp", - "/tmp", -@@ -28518,6 +28595,8 @@ static const char *unixTempFileDir(void) - azDirs[0] = sqlite3_temp_directory; - if( !azDirs[1] ) azDirs[1] = getenv("SQLITE_TMPDIR"); - if( !azDirs[2] ) azDirs[2] = getenv("TMPDIR"); -+ if( !azDirs[3] ) azDirs[2] = getenv("TMP"); -+ if( !azDirs[4] ) azDirs[3] = getenv("TEMP"); - for(i=0; iopenFlags = openFlags; - } -@@ -28908,7 +28987,7 @@ static int unixOpen( - noLock = eType!=SQLITE_OPEN_MAIN_DB; - - --#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE -+#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE && !defined(__CYGWIN__) - if( fstatfs(fd, &fsInfo) == -1 ){ - ((unixFile*)pFile)->lastErrno = errno; - robust_close(p, fd, __LINE__); -@@ -28926,7 +29005,7 @@ static int unixOpen( - if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC; - if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI; - --#if SQLITE_ENABLE_LOCKING_STYLE -+#if SQLITE_ENABLE_LOCKING_STYLE && !defined(__CYGWIN__) - #if SQLITE_PREFER_PROXY_LOCKING - isAutoProxy = 1; - #endif -@@ -29248,7 +29327,7 @@ static int unixSleep(sqlite3_vfs *NotUse - ** sqlite3OsCurrentTime() during testing. - */ - #ifdef SQLITE_TEST --SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */ -+SQLITE_API extern int sqlite3_current_time; /* Fake system time in seconds since 1970. */ - #endif - - /* -@@ -30507,7 +30586,12 @@ static int proxyClose(sqlite3_file *id) - ** necessarily been initialized when this routine is called, and so they - ** should not be used. - */ --SQLITE_API int sqlite3_os_init(void){ -+#if SQLITE_OS_WIN -+SQLITE_API int sqlite3_os_unix_init(void){ -+#else -+SQLITE_API int sqlite3_os_init(void){ -+#endif -+ - /* - ** The following macro defines an initializer for an sqlite3_vfs object. - ** The name of the VFS is NAME. The pAppData is a pointer to a pointer -@@ -30561,9 +30645,12 @@ SQLITE_API int sqlite3_os_init(void){ - ** array cannot be const. - */ - static sqlite3_vfs aVfs[] = { --#if SQLITE_ENABLE_LOCKING_STYLE && (OS_VXWORKS || defined(__APPLE__)) -+#if SQLITE_ENABLE_LOCKING_STYLE && (OS_VXWORKS || defined(__APPLE__) || defined(__CYGWIN__)) - UNIXVFS("unix", autolockIoFinder ), - #else -+#ifdef __CYGWIN__ -+ UNIXVFS("winnt", winntIoFinder ), -+#endif - UNIXVFS("unix", posixIoFinder ), - #endif - UNIXVFS("unix-none", nolockIoFinder ), -@@ -30572,7 +30659,7 @@ SQLITE_API int sqlite3_os_init(void){ - #if OS_VXWORKS - UNIXVFS("unix-namedsem", semIoFinder ), - #endif --#if SQLITE_ENABLE_LOCKING_STYLE -+#if SQLITE_ENABLE_LOCKING_STYLE || defined(__CYGWIN__) - UNIXVFS("unix-posix", posixIoFinder ), - #if !OS_VXWORKS - UNIXVFS("unix-flock", flockIoFinder ), -@@ -30597,6 +30684,8 @@ SQLITE_API int sqlite3_os_init(void){ - return SQLITE_OK; - } - -+#undef aSyscall -+#if !SQLITE_OS_WIN - /* - ** Shutdown the operating system interface. - ** -@@ -30607,6 +30696,7 @@ SQLITE_API int sqlite3_os_init(void){ - SQLITE_API int sqlite3_os_end(void){ - return SQLITE_OK; - } -+#endif /* !SQLITE_OS_WIN */ - - #endif /* SQLITE_OS_UNIX */ - -@@ -30629,7 +30719,8 @@ SQLITE_API int sqlite3_os_end(void){ - #if SQLITE_OS_WIN /* This file is used for Windows only */ - - #ifdef __CYGWIN__ --# include -+/* # include */ -+/* # include */ - # include /* amalgamator: keep */ - #endif - -@@ -30881,6 +30972,13 @@ SQLITE_API int sqlite3_open_file_count = - #endif - - /* -+** This constant should already be defined (in the "WinDef.h" SDK file). -+*/ -+#ifndef MAX_PATH -+# define MAX_PATH (260) -+#endif -+ -+/* - ** Maximum pathname length (in chars) for Win32. This should normally be - ** MAX_PATH. - */ -@@ -30889,16 +30987,23 @@ SQLITE_API int sqlite3_open_file_count = - #endif - - /* -+** This constant should already be defined (in the "WinNT.h" SDK file). -+*/ -+#ifndef UNICODE_STRING_MAX_CHARS -+# define UNICODE_STRING_MAX_CHARS (32767) -+#endif -+ -+/* - ** Maximum pathname length (in chars) for WinNT. This should normally be --** 32767. -+** UNICODE_STRING_MAX_CHARS. - */ - #ifndef SQLITE_WINNT_MAX_PATH_CHARS --# define SQLITE_WINNT_MAX_PATH_CHARS (32767) -+# define SQLITE_WINNT_MAX_PATH_CHARS (UNICODE_STRING_MAX_CHARS) - #endif - - /* - ** Maximum pathname length (in bytes) for Win32. The MAX_PATH macro is in --** characters, so we allocate 3 bytes per character assuming worst-case of -+** characters, so we allocate 4 bytes per character assuming worst-case of - ** 4-bytes-per-character for UTF8. - */ - #ifndef SQLITE_WIN32_MAX_PATH_BYTES -@@ -30907,7 +31012,7 @@ SQLITE_API int sqlite3_open_file_count = - - /* - ** Maximum pathname length (in bytes) for WinNT. This should normally be --** 32767 * sizeof(WCHAR). -+** UNICODE_STRING_MAX_CHARS * sizeof(WCHAR). - */ - #ifndef SQLITE_WINNT_MAX_PATH_BYTES - # define SQLITE_WINNT_MAX_PATH_BYTES \ -@@ -30938,14 +31043,10 @@ SQLITE_API int sqlite3_open_file_count = - #endif - - /* --** Returns the string that should be used as the directory separator. -+** Returns the character that should be used as the directory separator. - */ --#ifndef winGetDirDep --# ifdef __CYGWIN__ --# define winGetDirDep() "/" --# else --# define winGetDirDep() "\\" --# endif -+#ifndef winGetDirSep -+# define winGetDirSep() '\\' - #endif - - /* -@@ -32003,7 +32104,7 @@ static void *winMemMalloc(int nBytes){ - assert( hHeap!=0 ); - assert( hHeap!=INVALID_HANDLE_VALUE ); - #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) -- assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); -+ assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); - #endif - assert( nBytes>=0 ); - p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes); -@@ -32025,7 +32126,7 @@ static void winMemFree(void *pPrior){ - assert( hHeap!=0 ); - assert( hHeap!=INVALID_HANDLE_VALUE ); - #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) -- assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); -+ assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); - #endif - if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */ - if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){ -@@ -32046,7 +32147,7 @@ static void *winMemRealloc(void *pPrior, - assert( hHeap!=0 ); - assert( hHeap!=INVALID_HANDLE_VALUE ); - #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) -- assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); -+ assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); - #endif - assert( nBytes>=0 ); - if( !pPrior ){ -@@ -32074,7 +32175,7 @@ static int winMemSize(void *p){ - assert( hHeap!=0 ); - assert( hHeap!=INVALID_HANDLE_VALUE ); - #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) -- assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); -+ assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, p) ); - #endif - if( !p ) return 0; - n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p); -@@ -33281,8 +33382,7 @@ static int winTruncate(sqlite3_file *id, - ** Count the number of fullsyncs and normal syncs. This is used to test - ** that syncs and fullsyncs are occuring at the right times. - */ --SQLITE_API int sqlite3_sync_count = 0; --SQLITE_API int sqlite3_fullsync_count = 0; -+extern int sqlite3_sync_count, sqlite3_fullsync_count; - #endif - - /* -@@ -34811,12 +34911,21 @@ static void *winConvertFromUtf8Filename( - - /* - ** This function returns non-zero if the specified UTF-8 string buffer --** ends with a directory separator character. -+** ends with a directory separator character or one was successfully -+** added to it. - */ --static int winEndsInDirSep(char *zBuf){ -+static int winMakeEndInDirSep(int nBuf, char *zBuf){ - if( zBuf ){ - int nLen = sqlite3Strlen30(zBuf); -- return nLen>0 && winIsDirSep(zBuf[nLen-1]); -+ if( nLen>0 ){ -+ if( winIsDirSep(zBuf[nLen-1]) ){ -+ return 1; -+ }else if( nLen+1mxPathname; -- zBuf = sqlite3MallocZero( nBuf+2 ); -+ nMax = pVfs->mxPathname; nBuf = nMax + 2; -+ zBuf = sqlite3MallocZero( nBuf ); - if( !zBuf ){ - OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); - return SQLITE_IOERR_NOMEM; -@@ -34854,11 +34964,21 @@ static int winGetTempname(sqlite3_vfs *p - ** has been explicitly set by the application; otherwise, use the one - ** configured by the operating system. - */ -- assert( nBuf>30 ); -+ nDir = nMax - (nPre + 15); -+ assert( nDir>0 ); - if( sqlite3_temp_directory ){ -- sqlite3_snprintf(nBuf-30, zBuf, "%s%s", sqlite3_temp_directory, -- winEndsInDirSep(sqlite3_temp_directory) ? "" : -- winGetDirDep()); -+ int nDirLen = sqlite3Strlen30(sqlite3_temp_directory); -+ if( nDirLen>0 ){ -+ if( !winIsDirSep(sqlite3_temp_directory[nDirLen-1]) ){ -+ nDirLen++; -+ } -+ if( nDirLen>nDir ){ -+ sqlite3_free(zBuf); -+ OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n")); -+ return winLogError(SQLITE_ERROR, 0, "winGetTempname1", 0); -+ } -+ sqlite3_snprintf(nMax, zBuf, "%s", sqlite3_temp_directory); -+ } - } - #if defined(__CYGWIN__) - else{ -@@ -34887,8 +35007,8 @@ static int winGetTempname(sqlite3_vfs *p - if( zDir==0 ) continue; - /* If the path starts with a drive letter followed by the colon - ** character, assume it is already a native Win32 path; otherwise, -- ** it must be converted to a native Win32 path prior via the Cygwin -- ** API prior to using it. -+ ** it must be converted to a native Win32 path via the Cygwin API -+ ** prior to using it. - */ - if( winIsDriveLetterAndColon(zDir) ){ - zConverted = winConvertFromUtf8Filename(zDir); -@@ -34898,13 +35018,13 @@ static int winGetTempname(sqlite3_vfs *p - return SQLITE_IOERR_NOMEM; - } - if( winIsDir(zConverted) ){ -- sqlite3_snprintf(nBuf-30, zBuf, "%s", zDir); -+ sqlite3_snprintf(nMax, zBuf, "%s", zDir); - sqlite3_free(zConverted); - break; - } - sqlite3_free(zConverted); - }else{ -- zConverted = sqlite3MallocZero( nBuf+1 ); -+ zConverted = sqlite3MallocZero( nMax+1 ); - if( !zConverted ){ - sqlite3_free(zBuf); - OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); -@@ -34912,12 +35032,12 @@ static int winGetTempname(sqlite3_vfs *p - } - if( cygwin_conv_path( - osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir, -- zConverted, nBuf+1)<0 ){ -+ zConverted, nMax+1)<0 ){ - sqlite3_free(zConverted); - sqlite3_free(zBuf); - OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n")); - return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno, -- "winGetTempname1", zDir); -+ "winGetTempname2", zDir); - } - if( winIsDir(zConverted) ){ - /* At this point, we know the candidate directory exists and should -@@ -34932,12 +35052,12 @@ static int winGetTempname(sqlite3_vfs *p - OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); - return SQLITE_IOERR_NOMEM; - } -- sqlite3_snprintf(nBuf-30, zBuf, "%s", zUtf8); -+ sqlite3_snprintf(nMax, zBuf, "%s", zUtf8); - sqlite3_free(zUtf8); - sqlite3_free(zConverted); - break; - }else{ -- sqlite3_snprintf(nBuf-30, zBuf, "%s", zConverted); -+ sqlite3_snprintf(nMax, zBuf, "%s", zConverted); - sqlite3_free(zConverted); - break; - } -@@ -34949,22 +35069,22 @@ static int winGetTempname(sqlite3_vfs *p - #elif !SQLITE_OS_WINRT && !defined(__CYGWIN__) - else if( osIsNT() ){ - char *zMulti; -- LPWSTR zWidePath = sqlite3MallocZero( nBuf*sizeof(WCHAR) ); -+ LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) ); - if( !zWidePath ){ - sqlite3_free(zBuf); - OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); - return SQLITE_IOERR_NOMEM; - } -- if( osGetTempPathW(nBuf, zWidePath)==0 ){ -+ if( osGetTempPathW(nMax, zWidePath)==0 ){ - sqlite3_free(zWidePath); - sqlite3_free(zBuf); - OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n")); - return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), -- "winGetTempname1", 0); -+ "winGetTempname2", 0); - } - zMulti = winUnicodeToUtf8(zWidePath); - if( zMulti ){ -- sqlite3_snprintf(nBuf-30, zBuf, "%s", zMulti); -+ sqlite3_snprintf(nMax, zBuf, "%s", zMulti); - sqlite3_free(zMulti); - sqlite3_free(zWidePath); - }else{ -@@ -34977,21 +35097,21 @@ static int winGetTempname(sqlite3_vfs *p - #ifdef SQLITE_WIN32_HAS_ANSI - else{ - char *zUtf8; -- char *zMbcsPath = sqlite3MallocZero( nBuf ); -+ char *zMbcsPath = sqlite3MallocZero( nMax ); - if( !zMbcsPath ){ - sqlite3_free(zBuf); - OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); - return SQLITE_IOERR_NOMEM; - } -- if( osGetTempPathA(nBuf, zMbcsPath)==0 ){ -+ if( osGetTempPathA(nMax, zMbcsPath)==0 ){ - sqlite3_free(zBuf); - OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n")); - return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), -- "winGetTempname2", 0); -+ "winGetTempname3", 0); - } - zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath); - if( zUtf8 ){ -- sqlite3_snprintf(nBuf-30, zBuf, "%s", zUtf8); -+ sqlite3_snprintf(nMax, zBuf, "%s", zUtf8); - sqlite3_free(zUtf8); - }else{ - sqlite3_free(zBuf); -@@ -35002,18 +35122,36 @@ static int winGetTempname(sqlite3_vfs *p - #endif /* SQLITE_WIN32_HAS_ANSI */ - #endif /* !SQLITE_OS_WINRT */ - -- /* Check that the output buffer is large enough for the temporary file -- ** name. If it is not, return SQLITE_ERROR. -+ /* -+ ** Check to make sure the temporary directory ends with an appropriate -+ ** separator. If it does not and there is not enough space left to add -+ ** one, fail. - */ -- nLen = sqlite3Strlen30(zBuf); -+ if( !winMakeEndInDirSep(nDir+1, zBuf) ){ -+ sqlite3_free(zBuf); -+ OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n")); -+ return winLogError(SQLITE_ERROR, 0, "winGetTempname4", 0); -+ } - -- if( (nLen + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){ -+ /* -+ ** Check that the output buffer is large enough for the temporary file -+ ** name in the following format: -+ ** -+ ** "/etilqs_XXXXXXXXXXXXXXX\0\0" -+ ** -+ ** If not, return SQLITE_ERROR. The number 17 is used here in order to -+ ** account for the space used by the 15 character random suffix and the -+ ** two trailing NUL characters. The final directory separator character -+ ** has already added if it was not already present. -+ */ -+ nLen = sqlite3Strlen30(zBuf); -+ if( (nLen + nPre + 17) > nBuf ){ - sqlite3_free(zBuf); - OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n")); -- return winLogError(SQLITE_ERROR, 0, "winGetTempname3", 0); -+ return winLogError(SQLITE_ERROR, 0, "winGetTempname5", 0); - } - -- sqlite3_snprintf(nBuf-18-nLen, zBuf+nLen, SQLITE_TEMP_FILE_PREFIX); -+ sqlite3_snprintf(nBuf-16-nLen, zBuf+nLen, SQLITE_TEMP_FILE_PREFIX); - - j = sqlite3Strlen30(zBuf); - sqlite3_randomness(15, &zBuf[j]); -@@ -35068,7 +35206,7 @@ static int winOpen( - int *pOutFlags /* Status return flags */ - ){ - HANDLE h; -- DWORD lastErrno; -+ DWORD lastErrno = 0; - DWORD dwDesiredAccess; - DWORD dwShareMode; - DWORD dwCreationDisposition; -@@ -35359,7 +35497,7 @@ static int winDelete( - int cnt = 0; - int rc; - DWORD attr; -- DWORD lastErrno; -+ DWORD lastErrno = 0; - void *zConverted; - UNUSED_PARAMETER(pVfs); - UNUSED_PARAMETER(syncDir); -@@ -35467,7 +35605,7 @@ static int winAccess( - ){ - DWORD attr; - int rc = 0; -- DWORD lastErrno; -+ DWORD lastErrno = 0; - void *zConverted; - UNUSED_PARAMETER(pVfs); - -@@ -35613,8 +35751,8 @@ static int winFullPathname( - return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno, - "winFullPathname1", zRelative); - } -- sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%s%s", -- sqlite3_data_directory, winGetDirDep(), zOut); -+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s", -+ sqlite3_data_directory, winGetDirSep(), zOut); - sqlite3_free(zOut); - }else{ - if( cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull)<0 ){ -@@ -35636,8 +35774,8 @@ static int winFullPathname( - ** for converting the relative path name to an absolute - ** one by prepending the data directory and a backslash. - */ -- sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%s%s", -- sqlite3_data_directory, winGetDirDep(), zRelative); -+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s", -+ sqlite3_data_directory, winGetDirSep(), zRelative); - }else{ - sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative); - } -@@ -35669,8 +35807,8 @@ static int winFullPathname( - ** for converting the relative path name to an absolute - ** one by prepending the data directory and a backslash. - */ -- sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%s%s", -- sqlite3_data_directory, winGetDirDep(), zRelative); -+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s", -+ sqlite3_data_directory, winGetDirSep(), zRelative); - return SQLITE_OK; - } - zConverted = winConvertFromUtf8Filename(zRelative); -@@ -35850,7 +35988,7 @@ static int winSleep(sqlite3_vfs *pVfs, i - ** sqlite3OsCurrentTime() during testing. - */ - #ifdef SQLITE_TEST --SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */ -+SQLITE_API extern int sqlite3_current_time; /* Fake system time in seconds since 1970. */ - #endif - - /* -@@ -36026,7 +36164,11 @@ SQLITE_API int sqlite3_os_init(void){ - sqlite3_vfs_register(&winLongPathVfs, 0); - #endif - -+#if SQLITE_OS_UNIX -+ return sqlite3_os_unix_init(); -+#else - return SQLITE_OK; -+#endif - } - - SQLITE_API int sqlite3_os_end(void){ diff --git a/sqlite/sqlite3-3.8.2-2.src.patch b/sqlite/sqlite3-3.8.2-2.src.patch new file mode 100644 index 00000000..6ac7aa0b --- /dev/null +++ b/sqlite/sqlite3-3.8.2-2.src.patch @@ -0,0 +1,1887 @@ +--- origsrc/sqlite-autoconf-3080200/README 2013-12-06 16:05:18.000000000 +0100 ++++ src/sqlite-autoconf-3080200/README 2013-12-09 12:10:52.530409600 +0100 +@@ -1,32 +1,166 @@ ++sqlite3 ++------------------------------------------- ++SQLite is a C library that implements an embeddable SQL database engine. ++Programs that link with the SQLite library can have SQL database access ++without running a separate RDBMS process. The distribution comes with a ++standalone command-line access program (sqlite) that can be used to ++administer an SQLite database and which serves as an example of how to ++use the SQLite library. ++ ++Runtime requirements: ++ cygwin-1.7 ++ libreadline7 ++ ++Build requirements: ++(besides corresponding devel packages) ++ binutils-2.23.51-1 ++ cygport-0.14.0-1 ++ gawk-4.1.0-1 ++ gcc-core-4.8.2-1 ++ libtool-2.4-1 ++ make-4.0-2 ++ sed-4.2.2-3 ++ ++Canonical homepage: ++ http://www.sqlite.org/ ++ ++------------------------------------------- ++ ++Build instructions: ++ unpack sqlite3-3.8.2-2-src.tar.bz2 ++ if you use setup to install this src package, it will be ++ unpacked under /usr/src automatically ++ cd /usr/src ++ cygport ./sqlite3-3.8.2-2.cygport all ++ ++This will create: ++ /usr/src/libsqlite3-devel-3.8.2-2.tar.bz2 ++ /usr/src/libsqlite3_0-3.8.2-2.tar.bz2 ++ /usr/src/sqlite3-3.8.2-2-src.tar.bz2 ++ /usr/src/sqlite3-3.8.2-2.tar.bz2 ++ ++------------------------------------------- ++ ++Files included in the binary packages: ++ ++(sqlite3) ++ /usr/bin/sqlite3.exe ++ /usr/share/doc/Cygwin/sqlite3.README ++ /usr/share/doc/sqlite3/README ++ /usr/share/man/man1/sqlite3.1.gz ++ ++(libsqlite3_0) ++ /usr/bin/cygsqlite3-0.dll ++ ++(libsqlite3-devel) ++ usr/include/sqlite3.h ++ usr/include/sqlite3ext.h ++ usr/lib/libsqlite3.a ++ usr/lib/libsqlite3.dll.a ++ usr/lib/libsqlite3.la ++ usr/lib/pkgconfig/sqlite3.pc ++ ++------------------ ++ ++Port Notes: ++ ++The Cygwin build contains VFS'es which are both win32 ++and unix compatible: ++ ++ "unix" (default): The real vfs is specified using ++ the environment variable CYGWIN_SQLITE_LOCKING, ++ which can have the following values: ++ "winnt": (default if CYGWIN_SQLITE_LOCKING not specified) ++ Uses Win32 file locking ++ "win32": Uses Win32 API, has 260 byte path limit. ++ "win32-longpath": Uses Win32 API. ++ "unix-posix": (default if CYGWIN_SQLITE_LOCKING starts with "unix") ++ "unix-excl": ++ "unix-namedsem": ++ "unix-flock": ++ "unix-dotfile": ++ "unix-none": ++ ++ All Cygwin VFS'es have an 4096 byte path limit, except "win32". ++ The "win32" and "win32-longpath" VFS's cannot be specified in ++ the "CYGWIN_SQLITE_LOCKING environment variable. ++ ++ Although the above values for CYGWIN_SQLITE_LOCKING are ++ recommended, the values "posix", "bsd" and "dotfile" are ++ recognized too, for compatibility with earlier Cygwin ++ SQLite builds. ++ ++----- version 3.8.2-2 ----- ++Version bump. ++New "unix-namedsem" VFS. ++Better UNC/Extended windows path handling in "win32", "winnt" ++and "win32-longpath" VFS's ++ ++Corresponds to upstream SQLite 3.8.2 ++ ++----- version 3.8.1-1 ----- ++Version bump. ++New "win32", "win32-longpath", and "winnt" VFS. The default is ++"unix", which behaves identical to earlier Cygwin versions. ++ ++Versions below starting with 3.5.8-1 were done by Warren Young ++ ++----- version 3.7.x-y ----- ++Version bump, not further specified here. ++ ++----- version 3.6.2-1 ----- ++Restored DLL version of library ++Distributing *.a in devel package instead of lib package. ++ ++----- version 3.5.8-1 ----- ++Fork of Cygwin Ports version, removing Tcl support since Cygwin doesn't ++distribute Tcl anymore. ++ ++Maintainer of versions below unknown. ++ ++----- version 3.5.6-1 ----- ++Version bump. ++Enabled the load_extension API for the PHP bindings. ++ ++----- version 3.5.4-1 ----- ++Version bump. ++ ++----- version 3.5.3-1 ----- ++Version bump. ++ ++----- version 3.5.2-1 ----- ++Version bump. ++ ++----- version 3.3.17-1 ----- ++Version bump. ++ ++----- version 3.3.12-1 ----- ++Version bump. ++ ++----- version 3.3.10-1 ----- ++Version bump. ++ ++----- version 3.3.7-1 ----- ++Version bump. Broke out separate binary packages. ++ ++----- version 3.3.5-1 ----- ++Version bump. ++ ++----- version 3.2.8-1 ----- ++Version bump. ++ ++----- version 3.2.7-1 ----- ++Version bump. ++ ++----- version 3.2.6-1 ----- ++Version bump. ++ ++----- version 3.2.1-1 ----- ++Version bump for 3.0 branch. ++ ++----- version 3.0.8-1 ----- ++Initial release of the 3.0 branch for Cygwin. ++This package can be installed in parallel with sqlite-2.8.x. + +-This package contains: +- +- * the SQLite library amalgamation (single file) source code distribution, +- * the shell.c file used to build the sqlite3 shell too, and +- * the sqlite3.h and sqlite3ext.h header files required to link programs +- and sqlite extensions against the installed libary. +- * autoconf/automake installation infrastucture. +- +-The generic installation instructions for autoconf/automake are found +-in the INSTALL file. +- +-The following SQLite specific boolean options are supported: +- +- --enable-readline use readline in shell tool [default=yes] +- --enable-threadsafe build a thread-safe library [default=yes] +- --enable-dynamic-extensions support loadable extensions [default=yes] +- +-The default value for the CFLAGS variable (options passed to the C +-compiler) includes debugging symbols in the build, resulting in larger +-binaries than are necessary. Override it on the configure command +-line like this: +- +- $ CFLAGS="-Os" ./configure +- +-to produce a smaller installation footprint. +- +-Other SQLite compilation parameters can also be set using CFLAGS. For +-example: +- +- $ CFLAGS="-Os -DSQLITE_OMIT_TRIGGERS" ./configure + ++Cygwin port maintained by Jan Nijtmans +--- origsrc/sqlite-autoconf-3080200/shell.c 2013-12-06 16:05:18.000000000 +0100 ++++ src/sqlite-autoconf-3080200/shell.c 2013-12-09 11:29:01.552789900 +0100 +@@ -1135,6 +1135,10 @@ static int display_stats( + fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n", iCur); + } + ++#ifndef SQLITE_STMTSTATUS_VM_STEP ++# define SQLITE_STMTSTATUS_VM_STEP 4 ++#endif ++ + if( pArg && pArg->out && db && pArg->pStmt ){ + iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, bReset); + fprintf(pArg->out, "Fullscan Steps: %d\n", iCur); +@@ -1142,8 +1146,10 @@ static int display_stats( + fprintf(pArg->out, "Sort Operations: %d\n", iCur); + iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset); + fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur); +- iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset); +- fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur); ++ if( sqlite3_libversion_number()>=3008000 ){ ++ iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset); ++ fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur); ++ } + } + + return 0; +@@ -3297,11 +3303,13 @@ int main(int argc, char **argv){ + int i; + int rc = 0; + ++#if 0 + if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){ + fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n", + sqlite3_sourceid(), SQLITE_SOURCE_ID); + exit(1); + } ++#endif + Argv0 = argv[0]; + main_init(&data); + stdin_is_interactive = isatty(0); +--- origsrc/sqlite-autoconf-3080200/sqlite3.1 2013-12-06 16:05:18.000000000 +0100 ++++ src/sqlite-autoconf-3080200/sqlite3.1 2013-12-09 11:29:08.147167100 +0100 +@@ -2,7 +2,7 @@ + .\" First parameter, NAME, should be all caps + .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection + .\" other parameters are allowed: see man(7), man(1) +-.TH SQLITE3 1 "Mon Apr 15 23:49:17 2002" ++.TH SQLITE3 1 "Mon Dec 2 14:31:01 2013" + .\" Please adjust this date whenever revising the manpage. + .\" + .\" Some roff macros, for reference: +@@ -49,7 +49,7 @@ a table named "memos" and insert a coupl + $ + .B sqlite3 mydata.db + .br +-SQLite version 3.1.3 ++SQLite version 3.8.2 + .br + Enter ".help" for instructions + .br +@@ -108,15 +108,24 @@ sqlite> + .B .help + .nf + .cc | ++.backup ?DB? FILE Backup DB (default "main") to FILE ++.bail ON|OFF Stop after hitting an error. Default OFF + .databases List names and files of attached databases + .dump ?TABLE? ... Dump the database in an SQL text format ++ If TABLE specified, only dump tables matching ++ LIKE pattern TABLE. + .echo ON|OFF Turn command echo on or off + .exit Exit this program +-.explain ON|OFF Turn output mode suitable for EXPLAIN on or off. ++.explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off. ++ With no args, it turns EXPLAIN on. + .header(s) ON|OFF Turn display of headers on or off + .help Show this message + .import FILE TABLE Import data from FILE into TABLE +-.indices TABLE Show names of all indices on TABLE ++.indices ?TABLE? Show names of all indices ++ If TABLE specified, only show indices for tables ++ matching LIKE pattern TABLE. ++.load FILE ?ENTRY? Load an extension library ++.log FILE|off Turn logging on or off. FILE can be stderr/stdout + .mode MODE ?TABLE? Set output mode where MODE is one of: + csv Comma-separated values + column Left-aligned columns. (See .width) +@@ -126,18 +135,29 @@ sqlite> + list Values delimited by .separator string + tabs Tab-separated values + tcl TCL list elements +-.nullvalue STRING Print STRING in place of NULL values ++.nullvalue STRING Use STRING in place of NULL values ++.open ?FILENAME? Close existing database and reopen FILENAME + .output FILENAME Send output to FILENAME + .output stdout Send output to the screen ++.print STRING... Print literal STRING + .prompt MAIN CONTINUE Replace the standard prompts + .quit Exit this program + .read FILENAME Execute SQL in FILENAME ++.restore ?DB? FILE Restore content of DB (default "main") from FILE + .schema ?TABLE? Show the CREATE statements ++ If TABLE specified, only show tables matching ++ LIKE pattern TABLE. + .separator STRING Change separator used by output mode and .import + .show Show the current values for various settings +-.tables ?PATTERN? List names of tables matching a LIKE pattern ++.stats ON|OFF Turn stats on or off ++.tables ?TABLE? List names of tables ++ If TABLE specified, only list tables matching ++ LIKE pattern TABLE. + .timeout MS Try opening locked tables for MS milliseconds +-.width NUM NUM ... Set column widths for "column" mode ++.trace FILE|off Output each SQL statement as it is run ++.vfsname ?AUX? Print the name of the VFS stack ++.width NUM1 NUM2 ... Set column widths for "column" mode ++.timer ON|OFF Turn the CPU timer measurement on or off + sqlite> + |cc . + .sp +@@ -147,25 +167,45 @@ sqlite> + .B sqlite3 + has the following options: + .TP +-.BI \-init\ file +-Read and execute commands from +-.I file +-, which can contain a mix of SQL statements and meta-commands. ++.B \-bail ++Stop after hitting an error. ++.TP ++.B \-batch ++force batch I/O. ++.TP ++.B \-column ++Query results will be displayed in a table like form, using ++whitespace characters to separate the columns and align the ++output. ++.TP ++.BI \-cmd\ command ++run ++.I command ++before reading stdin ++.TP ++.B \-csv ++Query results will be output as CSV format. + .TP + .B \-echo + Print commands before execution. + .TP ++.BI \-init\ file ++Read and execute commands from ++.I file ++, which can contain a mix of SQL statements and meta-commands. ++.TP + .B \-[no]header + Turn headers on or off. + .TP +-.B \-column +-Query results will be displayed in a table like form, using +-whitespace characters to separate the columns and align the +-output. ++.B \-help ++Show help on options and exit. + .TP + .B \-html + Query results will be output as simple HTML tables. + .TP ++.B \-interactive ++Force interactive I/O. ++.TP + .B \-line + Query results will be displayed with one value per line, rows + separated by a blank line. Designed to be easily parsed by +@@ -175,18 +215,23 @@ scripts or other programs + Query results will be displayed with the separator (|, by default) + character between each field value. The default. + .TP +-.BI \-separator\ separator +-Set output field separator. Default is '|'. +-.TP + .BI \-nullvalue\ string + Set string used to represent NULL values. Default is '' + (empty string). + .TP ++.BI \-separator\ separator ++Set output field separator. Default is '|'. ++.TP ++.B \-stats ++Print memory stats before each finalize. ++.TP + .B \-version + Show SQLite version. + .TP +-.B \-help +-Show help on options and exit. ++.BI \-vfs\ name ++Use ++.I name ++as the default VFS. + + + .SH INIT FILE +--- origsrc/sqlite-autoconf-3080200/sqlite3.c 2013-12-06 16:05:18.000000000 +0100 ++++ src/sqlite-autoconf-3080200/sqlite3.c 2013-12-09 12:27:15.946657800 +0100 +@@ -9726,7 +9726,10 @@ SQLITE_PRIVATE void sqlite3PCacheSetDefa + #if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER) + # define SQLITE_OS_OTHER 0 + # ifndef SQLITE_OS_WIN +-# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__) ++# if defined(__CYGWIN__) ++# define SQLITE_OS_WIN 1 ++# define SQLITE_OS_UNIX 1 ++# elif defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || defined(__BORLANDC__) + # define SQLITE_OS_WIN 1 + # define SQLITE_OS_UNIX 0 + # else +@@ -9742,7 +9745,7 @@ SQLITE_PRIVATE void sqlite3PCacheSetDefa + # endif + #endif + +-#if SQLITE_OS_WIN ++#if SQLITE_OS_WIN && !defined(__CYGWIN__) + # include + #endif + +@@ -10014,10 +10017,10 @@ SQLITE_PRIVATE int sqlite3OsCloseFree(sq + # define SQLITE_MUTEX_OMIT + #endif + #if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP) +-# if SQLITE_OS_UNIX +-# define SQLITE_MUTEX_PTHREADS +-# elif SQLITE_OS_WIN ++# if SQLITE_OS_WIN + # define SQLITE_MUTEX_W32 ++# elif SQLITE_OS_UNIX ++# define SQLITE_MUTEX_PTHREADS + # else + # define SQLITE_MUTEX_NOOP + # endif +@@ -18618,6 +18621,10 @@ SQLITE_PRIVATE sqlite3_mutex_methods con + ** This file contains the C functions that implement mutexes for win32 + */ + ++#ifdef __CYGWIN__ ++# include /* amalgamator: keep */ ++#endif ++ + /* + ** The code in this file is only used if we are compiling multithreaded + ** on a win32 system. +@@ -18714,6 +18721,9 @@ static int winMutex_isInit = 0; + */ + static LONG winMutex_lock = 0; + ++#if defined(__CYGWIN__) && defined(SQLITE_AMALGAMATION) ++static ++#endif + SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */ + + static int winMutexInit(void){ +@@ -23221,13 +23231,17 @@ SQLITE_PRIVATE const char *sqlite3Opcode + #include + #endif + ++#ifdef __CYGWIN__ ++# include ++#endif + +-#if SQLITE_ENABLE_LOCKING_STYLE ++#if SQLITE_ENABLE_LOCKING_STYLE || defined(__CYGWIN__) + # include +-# if OS_VXWORKS ++# if OS_VXWORKS || defined(__CYGWIN__) + # include + # include +-# else ++# endif ++# if !OS_VXWORKS + # include + # include + # endif +@@ -23272,7 +23286,15 @@ SQLITE_PRIVATE const char *sqlite3Opcode + /* + ** Maximum supported path-length. + */ +-#define MAX_PATHNAME 512 ++#ifndef MAX_PATHNAME ++# if defined(PATH_MAX) ++# define MAX_PATHNAME PATH_MAX ++# elif defined(MAXPATHLEN) ++# define MAX_PATHNAME MAXPATHLEN ++# else ++# define MAX_PATHNAME 512 ++# endif ++#endif + + /* + ** Only set the lastErrno if the error code is a real error and not +@@ -23327,10 +23349,10 @@ struct unixFile { + int sectorSize; /* Device sector size */ + int deviceCharacteristics; /* Precomputed device characteristics */ + #endif +-#if SQLITE_ENABLE_LOCKING_STYLE ++#if SQLITE_ENABLE_LOCKING_STYLE && !defined(__CYGWIN__) + int openFlags; /* The flags specified at open() */ + #endif +-#if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__) ++#if SQLITE_ENABLE_LOCKING_STYLE && !defined(__CYGWIN__) || defined(__APPLE__) + unsigned fsFlags; /* cached details from statfs() */ + #endif + #if OS_VXWORKS +@@ -23656,6 +23678,7 @@ static int openDirectory(const char*, in + ** testing and sandboxing. The following array holds the names and pointers + ** to all overrideable system calls. + */ ++#define aSyscall aUnixSyscall + static struct unix_syscall { + const char *zName; /* Name of the system call */ + sqlite3_syscall_ptr pCurrent; /* Current value of the system call */ +@@ -24152,7 +24175,9 @@ struct vxworksFileId { + ** variable: + */ + static struct vxworksFileId *vxworksFileList = 0; ++#endif /* OS_VXWORKS */ + ++#if OS_VXWORKS || defined(__CYGWIN__) + /* + ** Simplify a filename into its canonical form + ** by making the following changes: +@@ -24171,7 +24196,13 @@ static int vxworksSimplifyName(char *z, + while( n>1 && z[n-1]=='/' ){ n--; } + for(i=j=0; ictrlFlags |= UNIXFILE_EXCL; ++ ioMethods = &posixIoMethods; ++ }else if( sqlite3_stricmp(strategy, "posix") == 0 ){ ++ ioMethods = &posixIoMethods; ++ }else if( sqlite3_stricmp(strategy, "bsd") == 0 ++ || sqlite3_stricmp(strategy, "flock") == 0 ){ ++ ioMethods = &flockIoMethods; ++ }else if( sqlite3_stricmp(strategy, "dotfile") == 0 ){ ++ ioMethods = &dotlockIoMethods; ++ }else if( sqlite3_strnicmp(strategy, "win", 3) == 0 ++ || sqlite3_stricmp(strategy, "nfs") == 0 ){ ++ /* Not reasonable, fall back to default */ ++ ioMethods = &winntIoMethods; ++ }else if( sqlite3_stricmp(strategy, "none") == 0 ){ ++ ioMethods = &nolockIoMethods; ++ } ++ } ++ } ++ return ioMethods; ++} ++static const sqlite3_io_methods ++ *(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl; ++ ++#endif /* OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE */ ++ + /* + ** An abstract type for a pointer to a IO method finder function: + */ +@@ -28597,7 +28698,7 @@ static int fillInUnixFile( + pNew->lockingContext = zLockFile; + } + +-#if OS_VXWORKS ++#if OS_VXWORKS || defined(__CYGWIN__) + else if( pLockingStyle == &semIoMethods ){ + /* Named semaphore locking uses the file path so it needs to be + ** included in the semLockingContext +@@ -28607,8 +28708,14 @@ static int fillInUnixFile( + if( (rc==SQLITE_OK) && (pNew->pInode->pSem==NULL) ){ + char *zSemName = pNew->pInode->aSemName; + int n; ++#if OS_VXWORKS + sqlite3_snprintf(MAX_PATHNAME, zSemName, "/%s.sem", + pNew->pId->zCanonicalName); ++#else ++ sqlite3_snprintf(MAX_PATHNAME, zSemName, "/%s.sem", ++ zFilename); ++ vxworksSimplifyName(zSemName, MAX_PATHNAME); ++#endif + for( n=1; zSemName[n]; n++ ) + if( zSemName[n]=='/' ) zSemName[n] = '_'; + pNew->pInode->pSem = sem_open(zSemName, O_CREAT, 0666, 1); +@@ -28620,6 +28727,15 @@ static int fillInUnixFile( + unixLeaveMutex(); + } + #endif ++ ++#if defined(__CYGWIN__) ++ else if( pLockingStyle == &winntIoMethods ){ ++ if ((osFcntl(h, F_LCK_MANDATORY, 1) != 0) && (errno != EINVAL)) { ++ /* The API exists but it refused to enable mandatory locking! */ ++ rc = SQLITE_IOERR_ACCESS; ++ } ++ } ++#endif + + pNew->lastErrno = 0; + #if OS_VXWORKS +@@ -28649,6 +28765,8 @@ static const char *unixTempFileDir(void) + 0, + 0, + 0, ++ 0, ++ 0, + "/var/tmp", + "/usr/tmp", + "/tmp", +@@ -28661,6 +28779,8 @@ static const char *unixTempFileDir(void) + azDirs[0] = sqlite3_temp_directory; + if( !azDirs[1] ) azDirs[1] = getenv("SQLITE_TMPDIR"); + if( !azDirs[2] ) azDirs[2] = getenv("TMPDIR"); ++ if( !azDirs[3] ) azDirs[2] = getenv("TMP"); ++ if( !azDirs[4] ) azDirs[3] = getenv("TEMP"); + for(i=0; iopenFlags = openFlags; + } +@@ -29051,7 +29171,7 @@ static int unixOpen( + noLock = eType!=SQLITE_OPEN_MAIN_DB; + + +-#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE ++#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE && !defined(__CYGWIN__) + if( fstatfs(fd, &fsInfo) == -1 ){ + ((unixFile*)pFile)->lastErrno = errno; + robust_close(p, fd, __LINE__); +@@ -29069,7 +29189,7 @@ static int unixOpen( + if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC; + if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI; + +-#if SQLITE_ENABLE_LOCKING_STYLE ++#if SQLITE_ENABLE_LOCKING_STYLE && !defined(__CYGWIN__) + #if SQLITE_PREFER_PROXY_LOCKING + isAutoProxy = 1; + #endif +@@ -29211,6 +29331,13 @@ static int unixAccess( + } + + ++#if SQLITE_OS_WIN ++# if defined(SQLITE_AMALGAMATION) ++ static ++# endif ++ void winSimplifyName(char *z); ++#endif ++ + /* + ** Turn a relative pathname into a full pathname. The relative path + ** is stored as a nul-terminated string in the buffer pointed to by +@@ -29226,6 +29353,9 @@ static int unixFullPathname( + int nOut, /* Size of output buffer in bytes */ + char *zOut /* Output buffer */ + ){ ++#ifdef __CYGWIN__ ++ int i; ++#endif + + /* It's odd to simulate an io-error here, but really this is just + ** using the io-error infrastructure to test that SQLite handles this +@@ -29238,6 +29368,35 @@ static int unixFullPathname( + UNUSED_PARAMETER(pVfs); + + zOut[nOut-1] = '\0'; ++#ifdef __CYGWIN__ ++ if( sqlite3Isalpha(zPath[0]) && (zPath[1]==':') ++ && ((zPath[2]=='\\') || (zPath[2]=='/')) ){ ++ int nDrive; ++ char temp[4]; ++ temp[0] = zPath[0]; ++ memcpy(&temp[1], ":\\", 3); ++ cygwin_conv_path(CCP_WIN_A_TO_POSIX, temp, zOut, nOut); ++ nDrive = (int)strlen(zOut); ++ sqlite3_snprintf(nOut-nDrive, &zOut[nDrive], "%s", zPath+2); ++ }else if( ((zPath[0]=='\\') || (zPath[0]=='/')) && ((zPath[1]=='\\') || (zPath[1]=='/')) ++ && (zPath[2]=='?') && ((zPath[3]=='\\') || (zPath[3]=='/')) && sqlite3Isalpha(zPath[4]) ++ && (zPath[5]==':') && ((zPath[6]=='\\') || (zPath[6]=='/')) ){ ++ int nDrive; ++ char temp[4]; ++ temp[0] = zPath[4]; ++ memcpy(&temp[1], ":\\", 3); ++ cygwin_conv_path(CCP_WIN_A_TO_POSIX, temp, zOut, nOut); ++ nDrive = (int)strlen(zOut); ++ sqlite3_snprintf(nOut-nDrive, &zOut[nDrive], "%s", zPath+6); ++ }else if( ((zPath[0]=='\\') || (zPath[0]=='/')) && ((zPath[1]=='\\') || (zPath[1]=='/')) ++ && (zPath[2]=='?') && ((zPath[3]=='\\') || (zPath[3]=='/')) && sqlite3_strnicmp(zPath+4, "UNC", 3)==0 ++ && ((zPath[7]=='\\') || (zPath[7]=='/')) ){ ++ /* UNC paths in Cygwin start with "//" */ ++ sqlite3_snprintf(nOut, zOut, "//%s", zPath+8); ++ }else if( zPath[0]=='\\' ){ ++ sqlite3_snprintf(nOut, zOut, "%s", zPath); ++ }else ++#endif + if( zPath[0]=='/' ){ + sqlite3_snprintf(nOut, zOut, "%s", zPath); + }else{ +@@ -29248,6 +29407,9 @@ static int unixFullPathname( + nCwd = (int)strlen(zOut); + sqlite3_snprintf(nOut-nCwd, &zOut[nCwd], "/%s", zPath); + } ++#if SQLITE_OS_WIN && defined(__CYGWIN__) ++ winSimplifyName(zOut); ++#endif + return SQLITE_OK; + } + +@@ -29391,7 +29553,7 @@ static int unixSleep(sqlite3_vfs *NotUse + ** sqlite3OsCurrentTime() during testing. + */ + #ifdef SQLITE_TEST +-SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */ ++SQLITE_API extern int sqlite3_current_time; /* Fake system time in seconds since 1970. */ + #endif + + /* +@@ -29684,7 +29846,7 @@ static int proxyGetLockPath(const char * + */ + static int proxyCreateLockPath(const char *lockPath){ + int i, len; +- char buf[MAXPATHLEN]; ++ char buf[MAX_PATHNAME]; + int start = 0; + + assert(lockPath!=NULL); +@@ -29850,7 +30012,7 @@ static int proxyGetHostID(unsigned char + #define PROXY_CONCHVERSION 2 /* 1-byte header, 16-byte host id, path */ + #define PROXY_HEADERLEN 1 /* conch file header length */ + #define PROXY_PATHINDEX (PROXY_HEADERLEN+PROXY_HOSTIDLEN) +-#define PROXY_MAXCONCHLEN (PROXY_HEADERLEN+PROXY_HOSTIDLEN+MAXPATHLEN) ++#define PROXY_MAXCONCHLEN (PROXY_HEADERLEN+PROXY_HOSTIDLEN+MAX_PATHNAME) + + /* + ** Takes an open conch file, copies the contents to a new path and then moves +@@ -29861,7 +30023,7 @@ static int proxyGetHostID(unsigned char + static int proxyBreakConchLock(unixFile *pFile, uuid_t myHostID){ + proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext; + unixFile *conchFile = pCtx->conchFile; +- char tPath[MAXPATHLEN]; ++ char tPath[MAX_PATHNAME]; + char buf[PROXY_MAXCONCHLEN]; + char *cPath = pCtx->conchFilePath; + size_t readLen = 0; +@@ -29872,8 +30034,8 @@ static int proxyBreakConchLock(unixFile + UNUSED_PARAMETER(myHostID); + + /* create a new path by replace the trailing '-conch' with '-break' */ +- pathLen = strlcpy(tPath, cPath, MAXPATHLEN); +- if( pathLen>MAXPATHLEN || pathLen<6 || ++ pathLen = strlcpy(tPath, cPath, MAX_PATHNAME); ++ if( pathLen>MAX_PATHNAME || pathLen<6 || + (strlcpy(&tPath[pathLen-5], "break", 6) != 5) ){ + sqlite3_snprintf(sizeof(errmsg),errmsg,"path error (len %d)",(int)pathLen); + goto end_breaklock; +@@ -30006,7 +30168,7 @@ static int proxyTakeConch(unixFile *pFil + uuid_t myHostID; + int pError = 0; + char readBuf[PROXY_MAXCONCHLEN]; +- char lockPath[MAXPATHLEN]; ++ char lockPath[MAX_PATHNAME]; + char *tempLockPath = NULL; + int rc = SQLITE_OK; + int createConch = 0; +@@ -30058,8 +30220,8 @@ static int proxyTakeConch(unixFile *pFil + if( hostIdMatch ){ + size_t pathLen = (readLen - PROXY_PATHINDEX); + +- if( pathLen>=MAXPATHLEN ){ +- pathLen=MAXPATHLEN-1; ++ if( pathLen>=MAX_PATHNAME ){ ++ pathLen=MAX_PATHNAME-1; + } + memcpy(lockPath, &readBuf[PROXY_PATHINDEX], pathLen); + lockPath[pathLen] = 0; +@@ -30085,7 +30247,7 @@ static int proxyTakeConch(unixFile *pFil + + /* either the conch didn't match or we need to create a new one */ + if( !pCtx->lockProxyPath ){ +- proxyGetLockPath(pCtx->dbPath, lockPath, MAXPATHLEN); ++ proxyGetLockPath(pCtx->dbPath, lockPath, MAX_PATHNAME); + tempLockPath = lockPath; + /* create a copy of the lock path _only_ if the conch is taken */ + } +@@ -30113,9 +30275,9 @@ static int proxyTakeConch(unixFile *pFil + writeBuffer[0] = (char)PROXY_CONCHVERSION; + memcpy(&writeBuffer[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN); + if( pCtx->lockProxyPath!=NULL ){ +- strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath, MAXPATHLEN); ++ strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath, MAX_PATHNAME); + }else{ +- strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAXPATHLEN); ++ strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAX_PATHNAME); + } + writeSize = PROXY_PATHINDEX + strlen(&writeBuffer[PROXY_PATHINDEX]); + robust_ftruncate(conchFile->h, writeSize); +@@ -30294,7 +30456,7 @@ static int switchLockProxyPath(unixFile + + /* nothing to do if the path is NULL, :auto: or matches the existing path */ + if( !path || path[0]=='\0' || !strcmp(path, ":auto:") || +- (oldPath && !strncmp(oldPath, path, MAXPATHLEN)) ){ ++ (oldPath && !strncmp(oldPath, path, MAX_PATHNAME)) ){ + return SQLITE_OK; + }else{ + unixFile *lockProxy = pCtx->lockProxy; +@@ -30314,7 +30476,7 @@ static int switchLockProxyPath(unixFile + + /* + ** pFile is a file that has been opened by a prior xOpen call. dbPath +-** is a string buffer at least MAXPATHLEN+1 characters in size. ++** is a string buffer at least MAX_PATHNAME+1 characters in size. + ** + ** This routine find the filename associated with pFile and writes it + ** int dbPath. +@@ -30324,8 +30486,8 @@ static int proxyGetDbPathForUnixFile(uni + if( pFile->pMethod == &afpIoMethods ){ + /* afp style keeps a reference to the db path in the filePath field + ** of the struct */ +- assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN ); +- strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath, MAXPATHLEN); ++ assert( (int)strlen((char*)pFile->lockingContext)<=MAX_PATHNAME ); ++ strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath, MAX_PATHNAME); + } else + #endif + if( pFile->pMethod == &dotlockIoMethods ){ +@@ -30335,8 +30497,8 @@ static int proxyGetDbPathForUnixFile(uni + memcpy(dbPath, (char *)pFile->lockingContext, len + 1); + }else{ + /* all other styles use the locking context to store the db file path */ +- assert( strlen((char*)pFile->lockingContext)<=MAXPATHLEN ); +- strlcpy(dbPath, (char *)pFile->lockingContext, MAXPATHLEN); ++ assert( strlen((char*)pFile->lockingContext)<=MAX_PATHNAME ); ++ strlcpy(dbPath, (char *)pFile->lockingContext, MAX_PATHNAME); + } + return SQLITE_OK; + } +@@ -30351,7 +30513,7 @@ static int proxyGetDbPathForUnixFile(uni + */ + static int proxyTransformUnixFile(unixFile *pFile, const char *path) { + proxyLockingContext *pCtx; +- char dbPath[MAXPATHLEN+1]; /* Name of the database file */ ++ char dbPath[MAX_PATHNAME+1]; /* Name of the database file */ + char *lockPath=NULL; + int rc = SQLITE_OK; + +@@ -30472,7 +30634,7 @@ static int proxyFileControl(sqlite3_file + (proxyLockingContext*)pFile->lockingContext; + if( !strcmp(pArg, ":auto:") + || (pCtx->lockProxyPath && +- !strncmp(pCtx->lockProxyPath, proxyPath, MAXPATHLEN)) ++ !strncmp(pCtx->lockProxyPath, proxyPath, MAX_PATHNAME)) + ){ + rc = SQLITE_OK; + }else{ +@@ -30650,7 +30812,15 @@ static int proxyClose(sqlite3_file *id) + ** necessarily been initialized when this routine is called, and so they + ** should not be used. + */ +-SQLITE_API int sqlite3_os_init(void){ ++#if SQLITE_OS_WIN ++#if defined(SQLITE_AMALGAMATION) ++static ++#endif ++SQLITE_API int sqlite3_os_unix_init(void){ ++#else ++SQLITE_API int sqlite3_os_init(void){ ++#endif ++ + /* + ** The following macro defines an initializer for an sqlite3_vfs object. + ** The name of the VFS is NAME. The pAppData is a pointer to a pointer +@@ -30704,22 +30874,29 @@ SQLITE_API int sqlite3_os_init(void){ + ** array cannot be const. + */ + static sqlite3_vfs aVfs[] = { +-#if SQLITE_ENABLE_LOCKING_STYLE && (OS_VXWORKS || defined(__APPLE__)) ++#if SQLITE_ENABLE_LOCKING_STYLE && (OS_VXWORKS || defined(__APPLE__) || defined(__CYGWIN__)) + UNIXVFS("unix", autolockIoFinder ), + #else + UNIXVFS("unix", posixIoFinder ), + #endif ++#ifdef __CYGWIN__ ++ UNIXVFS("winnt", winntIoFinder ), ++#if !SQLITE_OS_WIN ++ UNIXVFS("win32", winntIoFinder ), ++ UNIXVFS("win32-longpath", winntIoFinder ), ++#endif ++#endif + UNIXVFS("unix-none", nolockIoFinder ), + UNIXVFS("unix-dotfile", dotlockIoFinder ), + UNIXVFS("unix-excl", posixIoFinder ), +-#if OS_VXWORKS ++#if OS_VXWORKS || defined(__CYGWIN__) + UNIXVFS("unix-namedsem", semIoFinder ), + #endif + #if SQLITE_ENABLE_LOCKING_STYLE + UNIXVFS("unix-posix", posixIoFinder ), +-#if !OS_VXWORKS +- UNIXVFS("unix-flock", flockIoFinder ), + #endif ++#if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS || defined(__CYGWIN__) ++ UNIXVFS("unix-flock", flockIoFinder ), + #endif + #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) + UNIXVFS("unix-afp", afpIoFinder ), +@@ -30731,7 +30908,11 @@ SQLITE_API int sqlite3_os_init(void){ + + /* Double-check that the aSyscall[] array has been constructed + ** correctly. See ticket [bb3a86e890c8e96ab] */ ++#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 + assert( ArraySize(aSyscall)==24 ); ++#else ++ assert( ArraySize(aSyscall)==21 ); ++#endif + + /* Register all VFSes defined in the aVfs[] array */ + for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ +@@ -30740,6 +30921,8 @@ SQLITE_API int sqlite3_os_init(void){ + return SQLITE_OK; + } + ++#undef aSyscall ++#if !SQLITE_OS_WIN + /* + ** Shutdown the operating system interface. + ** +@@ -30750,6 +30933,7 @@ SQLITE_API int sqlite3_os_init(void){ + SQLITE_API int sqlite3_os_end(void){ + return SQLITE_OK; + } ++#endif /* !SQLITE_OS_WIN */ + + #endif /* SQLITE_OS_UNIX */ + +@@ -30772,8 +30956,15 @@ SQLITE_API int sqlite3_os_end(void){ + #if SQLITE_OS_WIN /* This file is used for Windows only */ + + #ifdef __CYGWIN__ +-# include ++/* # include */ ++# include /* amalgamator: keep */ ++# include /* amalgamator: keep */ + # include /* amalgamator: keep */ ++#else ++enum { ++ CCP_POSIX_TO_WIN_W=1, ++ CCP_WIN_A_TO_POSIX ++}; + #endif + + /* +@@ -31002,7 +31193,8 @@ SQLITE_API int sqlite3_open_file_count = + ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions + ** based on the sub-platform)? + */ +-#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI) ++#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI) \ ++ && !defined(_WIN64) && !defined(__x86_64__) + # define SQLITE_WIN32_HAS_ANSI + #endif + +@@ -31625,7 +31817,8 @@ static struct win_syscall { + + #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent) + +-#if !defined(SQLITE_OMIT_LOAD_EXTENSION) ++#if !defined(SQLITE_OMIT_LOAD_EXTENSION) || \ ++ (SQLITE_OS_WINNT && !defined(__CYGWIN__)) + #if SQLITE_OS_WINCE + /* The GetProcAddressA() routine is only available on Windows CE. */ + { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 }, +@@ -31686,8 +31879,7 @@ static struct win_syscall { + + #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent) + +-#if defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_GETVERSIONEX) && \ +- SQLITE_WIN32_GETVERSIONEX ++#if defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_GETVERSIONEX + { "GetVersionExA", (SYSCALL)GetVersionExA, 0 }, + #else + { "GetVersionExA", (SYSCALL)0, 0 }, +@@ -31697,7 +31889,7 @@ static struct win_syscall { + LPOSVERSIONINFOA))aSyscall[34].pCurrent) + + #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ +- defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX ++ SQLITE_WIN32_GETVERSIONEX + { "GetVersionExW", (SYSCALL)GetVersionExW, 0 }, + #else + { "GetVersionExW", (SYSCALL)0, 0 }, +@@ -32012,6 +32204,73 @@ static struct win_syscall { + #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \ + LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[75].pCurrent) + ++#if SQLITE_OS_WINNT && defined(SQLITE_WIN32_HAS_ANSI) && !defined(__CYGWIN__) ++ { "GetModuleHandleA", (SYSCALL)GetModuleHandleA, 0 }, ++#else ++ { "GetModuleHandleA", (SYSCALL)0, 0 }, ++#endif ++ ++#define osGetModuleHandleA ((HMODULE(*)(LPCSTR))aSyscall[76].pCurrent) ++ ++#if SQLITE_OS_WINNT && defined(SQLITE_WIN32_HAS_WIDE) && !defined(__CYGWIN__) ++ { "GetModuleHandleW", (SYSCALL)GetModuleHandleW, 0 }, ++#else ++ { "GetModuleHandleW", (SYSCALL)0, 0 }, ++#endif ++ ++#define osGetModuleHandleW ((HMODULE(*)(LPCWSTR))aSyscall[77].pCurrent) ++ ++#if defined(__CYGWIN__) ++ { "getenv", (SYSCALL)getenv, 0 }, ++#else ++ { "getenv", (SYSCALL)0, 0 }, ++#endif ++ ++#define getenv ((const char *(*)(const char *))aSyscall[78].pCurrent) ++ ++#if defined(__CYGWIN__) ++ { "getcwd", (SYSCALL)getcwd, 0 }, ++#else ++ { "getcwd", (SYSCALL)0, 0 }, ++#endif ++ ++#define getcwd ((char*(*)(char*,size_t))aSyscall[79].pCurrent) ++ ++#if defined(__CYGWIN__) ++ { "__errno", (SYSCALL)__errno, 0 }, ++#else ++ { "__errno", (SYSCALL)0, 0 }, ++#endif ++ ++#define osErrno (*((int*(*)(void))aSyscall[80].pCurrent)()) ++ ++#if defined(__CYGWIN__) && defined(SQLITE_WIN32_HAS_WIDE) ++ { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 }, ++#else ++ { "cygwin_conv_path", (SYSCALL)0, 0 }, ++#endif ++ ++#define cygwin_conv_path ((ssize_t(*)(unsigned int, \ ++ const void *, void *, size_t))aSyscall[81].pCurrent) ++ ++#if defined(__CYGWIN__) && defined(SQLITE_WIN32_HAS_ANSI) ++ { "cygwin_conv_to_full_win32_path", (SYSCALL)cygwin_conv_to_full_win32_path,0 }, ++#else ++ { "cygwin_conv_to_full_win32_path", (SYSCALL)0, 0 }, ++#endif ++ ++#define cygwin_conv_to_full_win32_path ((void(*)(const char *, \ ++ char *))aSyscall[82].pCurrent) ++ ++#if defined(__CYGWIN__) && defined(SQLITE_WIN32_HAS_ANSI) ++ { "cygwin_conv_to_full_posix_path", (SYSCALL)cygwin_conv_to_full_posix_path,0 }, ++#else ++ { "cygwin_conv_to_full_posix_path", (SYSCALL)0, 0 }, ++#endif ++ ++#define cygwin_conv_to_full_posix_path ((void(*)(const char *, \ ++ char *))aSyscall[83].pCurrent) ++ + }; /* End of the overrideable system calls */ + + /* +@@ -32185,6 +32444,7 @@ SQLITE_API int sqlite3_win32_reset_heap( + } + #endif /* SQLITE_WIN32_MALLOC */ + ++#ifndef __CYGWIN__ + /* + ** This function outputs the specified (ANSI) string to the Win32 debugger + ** (if available). +@@ -32221,6 +32481,7 @@ SQLITE_API void sqlite3_win32_write_debu + } + #endif + } ++#endif /* !__CYGWIN__ */ + + /* + ** The following routine suspends the current thread for at least ms +@@ -32230,6 +32491,9 @@ SQLITE_API void sqlite3_win32_write_debu + static HANDLE sleepObj = NULL; + #endif + ++#if defined(__CYGWIN__) && defined(SQLITE_AMALGAMATION) ++static ++#endif + SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds){ + #if SQLITE_OS_WINRT + if ( sleepObj==NULL ){ +@@ -32255,9 +32519,9 @@ SQLITE_API void sqlite3_win32_sleep(DWOR + ** the LockFileEx() API. + */ + +-#if !defined(SQLITE_WIN32_GETVERSIONEX) || !SQLITE_WIN32_GETVERSIONEX ++#if !SQLITE_WIN32_GETVERSIONEX + # define osIsNT() (1) +-#elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI) ++#elif !defined(SQLITE_WIN32_HAS_ANSI) + # define osIsNT() (1) + #elif !defined(SQLITE_WIN32_HAS_WIDE) + # define osIsNT() (0) +@@ -32487,9 +32751,12 @@ SQLITE_PRIVATE void sqlite3MemSetDefault + /* + ** Convert a UTF-8 string to Microsoft Unicode (UTF-16?). + ** +-** Space to hold the returned string is obtained from malloc. ++** Space to hold the returned string is obtained from malloc, ++** unless buf is not NULL and the needed size is less than ++** SQLITE_WIN32_MAX_PATH_CHARS bytes. As a conveniance, the ++** Unicode string "\\?\" is always prepended to the result. + */ +-static LPWSTR winUtf8ToUnicode(const char *zFilename){ ++static LPWSTR winUtf8ToUnicode(const char *zFilename, void *buf){ + int nChar; + LPWSTR zWideFilename; + +@@ -32497,11 +32764,16 @@ static LPWSTR winUtf8ToUnicode(const cha + if( nChar==0 ){ + return 0; + } +- zWideFilename = sqlite3MallocZero( nChar*sizeof(zWideFilename[0]) ); +- if( zWideFilename==0 ){ +- return 0; ++ if( buf && (nChar < ((SQLITE_WIN32_MAX_PATH_CHARS-8)/sizeof(zWideFilename[0]))) ){ ++ zWideFilename = buf; ++ }else{ ++ zWideFilename = sqlite3Malloc( nChar*sizeof(zWideFilename[0])+8 ); ++ if( zWideFilename==0 ){ ++ return 0; ++ } + } +- nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, ++ memcpy(zWideFilename, L"\\\\?\\", 8); ++ nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename+4, + nChar); + if( nChar==0 ){ + sqlite3_free(zWideFilename); +@@ -32552,7 +32824,7 @@ static LPWSTR winMbcsToUnicode(const cha + if( nByte==0 ){ + return 0; + } +- zMbcsFilename = sqlite3MallocZero( nByte*sizeof(zMbcsFilename[0]) ); ++ zMbcsFilename = sqlite3Malloc( nByte*sizeof(zMbcsFilename[0]) ); + if( zMbcsFilename==0 ){ + return 0; + } +@@ -32581,7 +32853,7 @@ static char *winUnicodeToMbcs(LPCWSTR zW + if( nByte == 0 ){ + return 0; + } +- zFilename = sqlite3MallocZero( nByte ); ++ zFilename = sqlite3Malloc( nByte ); + if( zFilename==0 ){ + return 0; + } +@@ -32594,6 +32866,7 @@ static char *winUnicodeToMbcs(LPCWSTR zW + return zFilename; + } + ++#ifdef SQLITE_WIN32_HAS_ANSI + /* + ** Convert multibyte character string to UTF-8. Space to hold the + ** returned string is obtained from sqlite3_malloc(). +@@ -32619,15 +32892,17 @@ SQLITE_API char *sqlite3_win32_utf8_to_m + char *zFilenameMbcs; + LPWSTR zTmpWide; + +- zTmpWide = winUtf8ToUnicode(zFilename); ++ zTmpWide = winUtf8ToUnicode(zFilename, 0); + if( zTmpWide==0 ){ + return 0; + } +- zFilenameMbcs = winUnicodeToMbcs(zTmpWide); ++ zFilenameMbcs = winUnicodeToMbcs(zTmpWide+4); + sqlite3_free(zTmpWide); + return zFilenameMbcs; + } ++#endif /* SQLITE_WIN32_HAS_ANSI */ + ++#ifndef __CYGWIN__ + /* + ** This function sets the data directory or the temporary directory based on + ** the provided arguments. The type argument must be 1 in order to set the +@@ -32650,7 +32925,7 @@ SQLITE_API int sqlite3_win32_set_directo + || type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE + ); + assert( !ppDirectory || sqlite3MemdebugHasType(*ppDirectory, MEMTYPE_HEAP) ); +- if( ppDirectory ){ ++ if( !getenv && ppDirectory ){ + char *zValueUtf8 = 0; + if( zValue && zValue[0] ){ + zValueUtf8 = winUnicodeToUtf8(zValue); +@@ -32664,6 +32939,7 @@ SQLITE_API int sqlite3_win32_set_directo + } + return SQLITE_ERROR; + } ++#endif + + /* + ** The return value of winGetLastErrorMsg +@@ -32898,7 +33174,7 @@ static int winceCreateLock(const char *z + BOOL bLogged = FALSE; + BOOL bInit = TRUE; + +- zName = winUtf8ToUnicode(zFilename); ++ zName = winUtf8ToUnicode(zFilename, 0); + if( zName==0 ){ + /* out of memory */ + return SQLITE_IOERR_NOMEM; +@@ -32909,13 +33185,13 @@ static int winceCreateLock(const char *z + + /* Replace the backslashes from the filename and lowercase it + ** to derive a mutex name. */ +- zTok = osCharLowerW(zName); ++ zTok = osCharLowerW(zName+4); + for (;*zTok;zTok++){ + if (*zTok == '\\') *zTok = '_'; + } + + /* Create/open the named mutex */ +- pFile->hMutex = osCreateMutexW(NULL, FALSE, zName); ++ pFile->hMutex = osCreateMutexW(NULL, FALSE, zName+4); + if (!pFile->hMutex){ + pFile->lastErrno = osGetLastError(); + sqlite3_free(zName); +@@ -32930,10 +33206,10 @@ static int winceCreateLock(const char *z + ** case-sensitive, take advantage of that by uppercasing the mutex name + ** and using that as the shared filemapping name. + */ +- osCharUpperW(zName); ++ osCharUpperW(zName+4); + pFile->hShared = osCreateFileMappingW(INVALID_HANDLE_VALUE, NULL, + PAGE_READWRITE, 0, sizeof(winceLock), +- zName); ++ zName+4); + + /* Set a flag that indicates we're the first to create the memory so it + ** must be zero-initialized */ +@@ -33580,8 +33856,7 @@ static int winTruncate(sqlite3_file *id, + ** Count the number of fullsyncs and normal syncs. This is used to test + ** that syncs and fullsyncs are occuring at the right times. + */ +-SQLITE_API int sqlite3_sync_count = 0; +-SQLITE_API int sqlite3_fullsync_count = 0; ++extern int sqlite3_sync_count, sqlite3_fullsync_count; + #endif + + /* +@@ -34083,7 +34358,7 @@ static int winFileControl(sqlite3_file * + return SQLITE_OK; + } + case SQLITE_FCNTL_VFSNAME: { +- *(char**)pArg = sqlite3_mprintf("win32"); ++ *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); + OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); + return SQLITE_OK; + } +@@ -34165,7 +34440,7 @@ static int winDeviceCharacteristics(sqli + ** During sqlite3_os_init() we do a GetSystemInfo() + ** to get the granularity size. + */ +-SYSTEM_INFO winSysInfo; ++static SYSTEM_INFO winSysInfo; + + #ifndef SQLITE_OMIT_WAL + +@@ -35067,7 +35342,7 @@ static const sqlite3_io_methods winIoMet + ** sqlite3_vfs object. + */ + +-#if defined(__CYGWIN__) ++#if 0 + /* + ** Convert a filename from whatever the underlying operating system + ** supports for filenames into UTF-8. Space to hold the result is +@@ -35092,14 +35367,52 @@ static char *winConvertToUtf8Filename(co + ** Convert a UTF-8 filename into whatever form the underlying + ** operating system wants filenames in. Space to hold the result + ** is obtained from malloc and must be freed by the calling +-** function. ++** function, unless buf is not NULL and the needed size is less ++** than SQLITE_WIN32_MAX_PATH_CHARS bytes. This function should ++** never receive paths starthing with "\\?\", but it will produce ++** such paths when >=WinNT. + */ +-static void *winConvertFromUtf8Filename(const char *zFilename){ ++static void *winConvertFromUtf8Filename(const char *zFilename, void *buf){ + void *zConverted = 0; + if( osIsNT() ){ +- zConverted = winUtf8ToUnicode(zFilename); ++ if( (cygwin_conv_path!=NULL) && !(winIsDriveLetterAndColon(zFilename) ++ && winIsDirSep(zFilename[2]))){ ++ int nByte = cygwin_conv_path(CCP_POSIX_TO_WIN_W, zFilename, 0, 0); ++ if( nByte>0 ){ ++ if( buf && (nBytemxPathname +@@ -35923,7 +36297,73 @@ static int winFullPathname( + char *zFull /* Output buffer */ + ){ + +-#if defined(__CYGWIN__) ++#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__) ++ DWORD nByte; ++ void *zConverted; ++ char *zOut; ++#endif ++ ++ if( cygwin_conv_path || cygwin_conv_to_full_posix_path ){ ++ int i; ++ /* It's odd to simulate an io-error here, but really this is just ++ ** using the io-error infrastructure to test that SQLite handles this ++ ** function failing. This function could fail if, for example, the ++ ** current working directory has been unlinked. ++ */ ++ SimulateIOError( return SQLITE_ERROR ); ++ UNUSED_PARAMETER(pVfs); ++ ++ zFull[nFull-1] = '\0'; ++ if( winIsDirSep(zRelative[0]) && winIsDirSep(zRelative[1]) ++ && zRelative[2]=='?' && winIsDirSep(zRelative[3])){ ++ /* This is an extended path. Convert to non-extended form. */ ++ if( winIsDriveLetterAndColon(&zRelative[4]) && winIsDirSep(zRelative[6]) ){ ++ int nDrive; ++ char temp[4]; ++ temp[0] = zRelative[4]; ++ memcpy(&temp[1], ":\\", 3); ++ if( cygwin_conv_path ){ ++ cygwin_conv_path(CCP_WIN_A_TO_POSIX, temp, zFull, nFull); ++ }else{ ++ cygwin_conv_to_full_posix_path(temp, zFull); ++ } ++ nDrive = (int)strlen(zFull); ++ sqlite3_snprintf(nFull-nDrive, &zFull[nDrive], "%s", zRelative+4); ++ }else if( sqlite3_strnicmp(zRelative+4, "UNC", 3)==0 && winIsDirSep(zRelative[7]) ){ ++ /* UNC paths in Cygwin start with "//" */ ++ sqlite3_snprintf(nFull, zFull, "//%s", zRelative+8); ++ }else{ ++ /* Something wrong, no conversion */ ++ sqlite3_snprintf(nFull, zFull, "%s", zRelative); ++ } ++ }else if( winIsDriveLetterAndColon(zRelative) && winIsDirSep(zRelative[2]) ){ ++ int nDrive; ++ char temp[4]; ++ temp[0] = zRelative[0]; ++ memcpy(&temp[1], ":\\", 3); ++ if( cygwin_conv_path ){ ++ cygwin_conv_path(CCP_WIN_A_TO_POSIX, temp, zFull, nFull); ++ }else{ ++ cygwin_conv_to_full_posix_path(temp, zFull); ++ } ++ nDrive = (int)strlen(zFull); ++ sqlite3_snprintf(nFull-nDrive, &zFull[nDrive], "%s", zRelative+2); ++ }else if( getcwd && !winIsDirSep(zRelative[0]) ){ ++ int nCwd; ++ if( getcwd(zFull, nFull-1)==0 ){ ++ return winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)osErrno, "getcwd", zRelative); ++ } ++ nCwd = (int)strlen(zFull); ++ sqlite3_snprintf(nFull-nCwd, &zFull[nCwd], "/%s", zRelative); ++ }else{ ++ sqlite3_snprintf(nFull, zFull, "%s", zRelative); ++ } ++#if defined(_WIN32) || defined(__CYGWIN__) ++ winSimplifyName(zFull); ++#endif ++ return SQLITE_OK; ++ } ++#if 0 + SimulateIOError( return SQLITE_ERROR ); + UNUSED_PARAMETER(nFull); + assert( nFull>=pVfs->mxPathname ); +@@ -36000,9 +36440,11 @@ static int winFullPathname( + #endif + + #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__) ++#if 0 + DWORD nByte; + void *zConverted; + char *zOut; ++#endif + + /* If this path name begins with "/X:", where "X" is any alphabetic + ** character, discard the initial "/" from the pathname. +@@ -36028,7 +36470,7 @@ static int winFullPathname( + sqlite3_data_directory, winGetDirSep(), zRelative); + return SQLITE_OK; + } +- zConverted = winConvertFromUtf8Filename(zRelative); ++ zConverted = winConvertFromUtf8Filename(zRelative, 0); + if( zConverted==0 ){ + return SQLITE_IOERR_NOMEM; + } +@@ -36041,7 +36483,7 @@ static int winFullPathname( + "winFullPathname1", zRelative); + } + nByte += 3; +- zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) ); ++ zTemp = sqlite3Malloc( nByte*sizeof(zTemp[0]) ); + if( zTemp==0 ){ + sqlite3_free(zConverted); + return SQLITE_IOERR_NOMEM; +@@ -36067,7 +36509,7 @@ static int winFullPathname( + "winFullPathname3", zRelative); + } + nByte += 3; +- zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) ); ++ zTemp = sqlite3Malloc( nByte*sizeof(zTemp[0]) ); + if( zTemp==0 ){ + sqlite3_free(zConverted); + return SQLITE_IOERR_NOMEM; +@@ -36105,7 +36547,8 @@ static int winFullPathname( + */ + static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){ + HANDLE h; +- void *zConverted = winConvertFromUtf8Filename(zFilename); ++ char buf[SQLITE_WIN32_MAX_PATH_CHARS]; ++ void *zConverted = winConvertFromUtf8Filename(zFilename, buf); + UNUSED_PARAMETER(pVfs); + if( zConverted==0 ){ + return 0; +@@ -36122,7 +36565,9 @@ static void *winDlOpen(sqlite3_vfs *pVfs + h = osLoadLibraryA((char*)zConverted); + } + #endif +- sqlite3_free(zConverted); ++ if( zConverted!=buf ){ ++ sqlite3_free(zConverted); ++ } + return (void*)h; + } + static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){ +@@ -36205,7 +36650,7 @@ static int winSleep(sqlite3_vfs *pVfs, i + ** sqlite3OsCurrentTime() during testing. + */ + #ifdef SQLITE_TEST +-SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */ ++SQLITE_API extern int sqlite3_current_time; /* Fake system time in seconds since 1970. */ + #endif + + /* +@@ -36306,6 +36751,10 @@ static int winGetLastError(sqlite3_vfs * + return winGetLastErrorMsg(osGetLastError(), nBuf, zBuf); + } + ++#if SQLITE_OS_UNIX && !defined(SQLITE_AMALGAMATION) ++SQLITE_API int sqlite3_os_unix_init(void); ++#endif ++ + /* + ** Initialize and deinitialize the operating system interface. + */ +@@ -36360,10 +36809,12 @@ SQLITE_API int sqlite3_os_init(void){ + winNextSystemCall, /* xNextSystemCall */ + }; + #endif ++ int i; ++ HMODULE module; + + /* Double-check that the aSyscall[] array has been constructed + ** correctly. See ticket [bb3a86e890c8e96ab] */ +- assert( ArraySize(aSyscall)==76 ); ++ assert( ArraySize(aSyscall)==84 ); + + /* get memory map allocation granularity */ + memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); +@@ -36375,10 +36826,35 @@ SQLITE_API int sqlite3_os_init(void){ + assert( winSysInfo.dwAllocationGranularity>0 ); + assert( winSysInfo.dwPageSize>0 ); + ++#if SQLITE_OS_WINNT && !defined(__CYGWIN__) ++ if( osIsNT() ){ ++ module = osGetModuleHandleW(L"CYGWIN1.DLL"); ++ if( !module){ ++ module = osGetModuleHandleW(L"MSYS-1.0.DLL"); ++ } ++ }else{ ++ module = osGetModuleHandleA("CYGWIN1.DLL"); ++ if( !module){ ++ module = osGetModuleHandleA("MSYS-1.0.DLL"); ++ } ++ } ++ if( module ){ ++ for(i=78;i