/ Check-in [e85cfe9a]
Login

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

Overview
Comment:Use _commit() rather than FlushFileBuffers() as a substitute for fsync() on windows. Also cast for C++ and add support for SQLITE_FCNTL_VFSNAME.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | quota-stdio
Files: files | file ages | folders
SHA1: e85cfe9a17a2943ee0cf7915451ff6cc05908030
User & Date: drh 2011-12-15 17:42:35
Context
2011-12-15
17:44
Add stdio support to the quota VFS. check-in: 322bd15f user: drh tags: trunk
17:42
Use _commit() rather than FlushFileBuffers() as a substitute for fsync() on windows. Also cast for C++ and add support for SQLITE_FCNTL_VFSNAME. Closed-Leaf check-in: e85cfe9a user: drh tags: quota-stdio
2011-12-14
00:04
Harden the utf8-to-mbcs converter in the quota module against failures. check-in: 1cda511d user: drh tags: quota-stdio
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test_quota.c.

   405    405   #endif
   406    406   
   407    407   #if SQLITE_OS_UNIX
   408    408   # include <unistd.h>
   409    409   #endif
   410    410   #if SQLITE_OS_WIN
   411    411   # include <windows.h>
          412  +# include <io.h>
   412    413   #endif
   413    414   
   414    415   /*
   415    416   ** Translate UTF8 to MBCS for use in fopen() calls.  Return a pointer to the
   416    417   ** translated text..  Call quota_mbcs_free() to deallocate any memory
   417    418   ** used to store the returned pointer when done.
   418    419   */
................................................................................
   424    425     LPWSTR zTmpWide;   /* The UTF16 text */
   425    426     char *zMbcs;       /* The MBCS text */
   426    427     int codepage;      /* Code page used by fopen() */
   427    428   
   428    429     n = strlen(zUtf8);
   429    430     nWide = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, NULL, 0);
   430    431     if( nWide==0 ) return 0;
   431         -  zTmpWide = sqlite3_malloc( (nWide+1)*sizeof(zTmpWide[0]) );
          432  +  zTmpWide = (LPWSTR)sqlite3_malloc( (nWide+1)*sizeof(zTmpWide[0]) );
   432    433     if( zTmpWide==0 ) return 0;
   433    434     MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zTmpWide, nWide);
   434    435     codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
   435    436     nMbcs = WideCharToMultiByte(codepage, 0, zTmpWide, nWide, 0, 0, 0, 0);
   436         -  zMbcs = nMbcs ? sqlite3_malloc( nMbcs+1 ) : 0;
          437  +  zMbcs = nMbcs ? (char*)sqlite3_malloc( nMbcs+1 ) : 0;
   437    438     if( zMbcs ){
   438    439       WideCharToMultiByte(codepage, 0, zTmpWide, nWide, zMbcs, nMbcs, 0, 0);
   439    440     }
   440    441     sqlite3_free(zTmpWide);
   441    442     return zMbcs;
   442    443   #else
   443    444     return (char*)zUtf8;  /* No-op on unix */
................................................................................
   710    711     return pSubOpen->pMethods->xCheckReservedLock(pSubOpen, pResOut);
   711    712   }
   712    713   
   713    714   /* Pass xFileControl requests through to the original VFS unchanged.
   714    715   */
   715    716   static int quotaFileControl(sqlite3_file *pConn, int op, void *pArg){
   716    717     sqlite3_file *pSubOpen = quotaSubOpen(pConn);
   717         -  return pSubOpen->pMethods->xFileControl(pSubOpen, op, pArg);
          718  +  int rc = pSubOpen->pMethods->xFileControl(pSubOpen, op, pArg);
          719  +#if defined(SQLITE_FCNTL_VFSNAME)
          720  +  if( op==SQLITE_FCNTL_VFSNAME && rc==SQLITE_OK ){
          721  +    *(char**)pArg = sqlite3_mprintf("quota/%z", *(char**)pArg);
          722  +  }
          723  +#endif
          724  +  return rc;
   718    725   }
   719    726   
   720    727   /* Pass xSectorSize requests through to the original VFS unchanged.
   721    728   */
   722    729   static int quotaSectorSize(sqlite3_file *pConn){
   723    730     sqlite3_file *pSubOpen = quotaSubOpen(pConn);
   724    731     return pSubOpen->pMethods->xSectorSize(pSubOpen);
................................................................................
  1089   1096     int rc;
  1090   1097     rc = fflush(p->f);
  1091   1098     if( rc==0 && doFsync ){
  1092   1099   #if SQLITE_OS_UNIX
  1093   1100       rc = fsync(fileno(p->f));
  1094   1101   #endif
  1095   1102   #if SQLITE_OS_WIN
  1096         -    rc = 0==FlushFileBuffers((HANDLE)_fileno(p->f));
         1103  +    rc = _commit(_fileno(p->f));
  1097   1104   #endif
  1098   1105     }
  1099         -  return rc;
         1106  +  return rc!=0;
  1100   1107   }
  1101   1108   
  1102   1109   /*
  1103   1110   ** Seek on a quota_FILE stream.
  1104   1111   */
  1105   1112   int sqlite3_quota_fseek(quota_FILE *p, long offset, int whence){
  1106   1113     return fseek(p->f, offset, whence);