aboutsummaryrefslogtreecommitdiff
path: root/src/os_win.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2013-08-02 20:44:48 +0000
committerdrh <drh@noemail.net>2013-08-02 20:44:48 +0000
commit7fb30bd0dd4057c203415b7d1d0fe0a15e25a8f7 (patch)
treedd7ab4cd95b8b32df8e8f92df1ed4234744c2da1 /src/os_win.c
parent6f855952d07e32967b84c790201da4b45d849722 (diff)
parente0c7efd9ae6706b5e39093bcf2256569032c2b91 (diff)
downloadsqlite-7fb30bd0dd4057c203415b7d1d0fe0a15e25a8f7.tar.gz
sqlite-7fb30bd0dd4057c203415b7d1d0fe0a15e25a8f7.zip
Merge in the latest trunk changes, including partial indexes, the MAX_PATH
fix in os_win.c, and the sqlite3_cancel_auto_extension() API. FossilOrigin-Name: 7e1acb390770d1bd189fac7a3a7f96106f96e3a4
Diffstat (limited to 'src/os_win.c')
-rw-r--r--src/os_win.c84
1 files changed, 61 insertions, 23 deletions
diff --git a/src/os_win.c b/src/os_win.c
index bdf025aa4..10c431644 100644
--- a/src/os_win.c
+++ b/src/os_win.c
@@ -17,6 +17,7 @@
#ifdef __CYGWIN__
# include <sys/cygwin.h>
+# include <errno.h>
#endif
/*
@@ -230,6 +231,7 @@ struct winFile {
# define SQLITE_WIN32_HEAP_FLAGS (0)
#endif
+
/*
** The winMemData structure stores information required by the Win32-specific
** sqlite3_mem_methods implementation.
@@ -3694,10 +3696,10 @@ static int winMapfile(winFile *pFd, sqlite3_int64 nByte){
return SQLITE_OK;
}
assert( (nMap % winSysInfo.dwPageSize)==0 );
+ assert( sizeof(SIZE_T)==sizeof(sqlite3_int64) || nMap<=0xffffffff );
#if SQLITE_OS_WINRT
- pNew = osMapViewOfFileFromApp(pFd->hMap, flags, 0, nMap);
+ pNew = osMapViewOfFileFromApp(pFd->hMap, flags, 0, (SIZE_T)nMap);
#else
- assert( sizeof(SIZE_T)==sizeof(sqlite3_int64) || nMap<=0xffffffff );
pNew = osMapViewOfFile(pFd->hMap, flags, 0, 0, (SIZE_T)nMap);
#endif
if( pNew==NULL ){
@@ -3867,6 +3869,15 @@ static void *convertUtf8Filename(const char *zFilename){
}
/*
+** Maximum pathname length (in bytes) for windows. The MAX_PATH macro is
+** in characters, so we allocate 3 bytes per character assuming worst-case
+** 3-bytes-per-character UTF8.
+*/
+#ifndef SQLITE_WIN32_MAX_PATH
+# define SQLITE_WIN32_MAX_PATH (MAX_PATH*3)
+#endif
+
+/*
** Create a temporary file name in zBuf. zBuf must be big enough to
** hold at pVfs->mxPathname characters.
*/
@@ -3877,7 +3888,7 @@ static int getTempname(int nBuf, char *zBuf){
"0123456789";
size_t i, j;
int nTempPath;
- char zTempPath[MAX_PATH+2];
+ char zTempPath[SQLITE_WIN32_MAX_PATH+2];
/* 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
@@ -3885,19 +3896,21 @@ static int getTempname(int nBuf, char *zBuf){
*/
SimulateIOError( return SQLITE_IOERR );
- memset(zTempPath, 0, MAX_PATH+2);
-
if( sqlite3_temp_directory ){
- sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
+ sqlite3_snprintf(SQLITE_WIN32_MAX_PATH-30, zTempPath, "%s",
+ sqlite3_temp_directory);
}
#if !SQLITE_OS_WINRT
else if( isNT() ){
char *zMulti;
WCHAR zWidePath[MAX_PATH];
- osGetTempPathW(MAX_PATH-30, zWidePath);
+ if( osGetTempPathW(MAX_PATH-30, zWidePath)==0 ){
+ OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
+ return SQLITE_IOERR_GETTEMPPATH;
+ }
zMulti = unicodeToUtf8(zWidePath);
if( zMulti ){
- sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti);
+ sqlite3_snprintf(SQLITE_WIN32_MAX_PATH-30, zTempPath, "%s", zMulti);
sqlite3_free(zMulti);
}else{
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
@@ -3907,19 +3920,38 @@ static int getTempname(int nBuf, char *zBuf){
#ifdef SQLITE_WIN32_HAS_ANSI
else{
char *zUtf8;
- char zMbcsPath[MAX_PATH];
- osGetTempPathA(MAX_PATH-30, zMbcsPath);
+ char zMbcsPath[SQLITE_WIN32_MAX_PATH];
+ if( osGetTempPathA(SQLITE_WIN32_MAX_PATH-30, zMbcsPath)==0 ){
+ OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
+ return SQLITE_IOERR_GETTEMPPATH;
+ }
zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
if( zUtf8 ){
- sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8);
+ sqlite3_snprintf(SQLITE_WIN32_MAX_PATH-30, zTempPath, "%s", zUtf8);
sqlite3_free(zUtf8);
}else{
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
return SQLITE_IOERR_NOMEM;
}
}
-#endif
-#endif
+#else
+ else{
+ /*
+ ** Compiled without ANSI support and the current operating system
+ ** is not Windows NT; therefore, just zero the temporary buffer.
+ */
+ memset(zTempPath, 0, SQLITE_WIN32_MAX_PATH+2);
+ }
+#endif /* SQLITE_WIN32_HAS_ANSI */
+#else
+ else{
+ /*
+ ** Compiled for WinRT and the sqlite3_temp_directory is not set;
+ ** therefore, just zero the temporary buffer.
+ */
+ memset(zTempPath, 0, SQLITE_WIN32_MAX_PATH+2);
+ }
+#endif /* !SQLITE_OS_WINRT */
/* Check that the output buffer is large enough for the temporary file
** name. If it is not, return SQLITE_ERROR.
@@ -4005,7 +4037,7 @@ static int winOpen(
/* If argument zPath is a NULL pointer, this function is required to open
** a temporary file. Use this buffer to store the file name in.
*/
- char zTmpname[MAX_PATH+2]; /* Buffer used to create temp filename */
+ char zTmpname[SQLITE_WIN32_MAX_PATH+2]; /* Buffer used to create temp filename */
int rc = SQLITE_OK; /* Function Return Code */
#if !defined(NDEBUG) || SQLITE_OS_WINCE
@@ -4071,8 +4103,7 @@ static int winOpen(
*/
if( !zUtf8Name ){
assert(isDelete && !isOpenJournal);
- memset(zTmpname, 0, MAX_PATH+2);
- rc = getTempname(MAX_PATH+2, zTmpname);
+ rc = getTempname(SQLITE_WIN32_MAX_PATH+2, zTmpname);
if( rc!=SQLITE_OK ){
OSTRACE(("OPEN name=%s, rc=%s", zUtf8Name, sqlite3ErrName(rc)));
return rc;
@@ -4503,7 +4534,7 @@ static int winFullPathname(
#if defined(__CYGWIN__)
SimulateIOError( return SQLITE_ERROR );
UNUSED_PARAMETER(nFull);
- assert( pVfs->mxPathname>=MAX_PATH );
+ assert( pVfs->mxPathname>=SQLITE_WIN32_MAX_PATH );
assert( nFull>=pVfs->mxPathname );
if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){
/*
@@ -4512,14 +4543,21 @@ static int winFullPathname(
** for converting the relative path name to an absolute
** one by prepending the data directory and a slash.
*/
- char zOut[MAX_PATH+1];
- memset(zOut, 0, MAX_PATH+1);
- cygwin_conv_path(CCP_POSIX_TO_WIN_A|CCP_RELATIVE, zRelative, zOut,
- MAX_PATH+1);
+ char zOut[SQLITE_WIN32_MAX_PATH+1];
+ if( cygwin_conv_path(CCP_POSIX_TO_WIN_A|CCP_RELATIVE, zRelative, zOut,
+ SQLITE_WIN32_MAX_PATH+1)<0 ){
+ winLogError(SQLITE_CANTOPEN_FULLPATH, (DWORD)errno, "cygwin_conv_path",
+ zRelative);
+ return SQLITE_CANTOPEN_FULLPATH;
+ }
sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s\\%s",
sqlite3_data_directory, zOut);
}else{
- cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull);
+ if( cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull)<0 ){
+ winLogError(SQLITE_CANTOPEN_FULLPATH, (DWORD)errno, "cygwin_conv_path",
+ zRelative);
+ return SQLITE_CANTOPEN_FULLPATH;
+ }
}
return SQLITE_OK;
#endif
@@ -4861,7 +4899,7 @@ int sqlite3_os_init(void){
static sqlite3_vfs winVfs = {
3, /* iVersion */
sizeof(winFile), /* szOsFile */
- MAX_PATH, /* mxPathname */
+ SQLITE_WIN32_MAX_PATH, /* mxPathname */
0, /* pNext */
"win32", /* zName */
0, /* pAppData */