/ Check-in [bb06e157]
Login

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

Overview
Comment:The MAX_PATH constant in windows is measured in characters, so multiple by 3 to get the number of bytes assuming worst-case UTF8 pathnames.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bb06e1579022c24546ac5117a99846b3c37ef59b
User & Date: drh 2013-07-31 19:55:25
Context
2013-07-31
22:27
Use a new error code to represent a failure to get the configured temporary directory on Windows. check-in: c93d891b user: mistachkin tags: trunk
19:55
The MAX_PATH constant in windows is measured in characters, so multiple by 3 to get the number of bytes assuming worst-case UTF8 pathnames. check-in: bb06e157 user: drh tags: trunk
2013-07-30
15:10
Reduce the size of the stack required by the codeOneLoopStart() function in where.c. check-in: eb6d4278 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

   225    225   /*
   226    226    * The extra flags to use in calls to the Win32 heap APIs.  This value may be
   227    227    * zero for the default behavior.
   228    228    */
   229    229   #ifndef SQLITE_WIN32_HEAP_FLAGS
   230    230   #  define SQLITE_WIN32_HEAP_FLAGS     (0)
   231    231   #endif
          232  +
   232    233   
   233    234   /*
   234    235   ** The winMemData structure stores information required by the Win32-specific
   235    236   ** sqlite3_mem_methods implementation.
   236    237   */
   237    238   typedef struct winMemData winMemData;
   238    239   struct winMemData {
................................................................................
  3862   3863       zConverted = sqlite3_win32_utf8_to_mbcs(zFilename);
  3863   3864     }
  3864   3865   #endif
  3865   3866     /* caller will handle out of memory */
  3866   3867     return zConverted;
  3867   3868   }
  3868   3869   
         3870  +/*
         3871  +** Maximum pathname length (in bytes) for windows.  The MAX_PATH macro is
         3872  +** in characters, so we allocate 3 bytes per character assuming worst-case
         3873  +** 3-bytes-per-character UTF8.
         3874  +*/
         3875  +#ifndef SQLITE_WIN32_MAX_PATH
         3876  +#  define SQLITE_WIN32_MAX_PATH   (MAX_PATH*3)
         3877  +#endif
         3878  +
  3869   3879   /*
  3870   3880   ** Create a temporary file name in zBuf.  zBuf must be big enough to
  3871   3881   ** hold at pVfs->mxPathname characters.
  3872   3882   */
  3873   3883   static int getTempname(int nBuf, char *zBuf){
  3874   3884     static char zChars[] =
  3875   3885       "abcdefghijklmnopqrstuvwxyz"
  3876   3886       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  3877   3887       "0123456789";
  3878   3888     size_t i, j;
  3879   3889     int nTempPath;
  3880         -  char zTempPath[MAX_PATH+2];
         3890  +  char zTempPath[SQLITE_WIN32_MAX_PATH+2];
  3881   3891   
  3882   3892     /* It's odd to simulate an io-error here, but really this is just
  3883   3893     ** using the io-error infrastructure to test that SQLite handles this
  3884   3894     ** function failing. 
  3885   3895     */
  3886   3896     SimulateIOError( return SQLITE_IOERR );
  3887   3897   
  3888         -  memset(zTempPath, 0, MAX_PATH+2);
         3898  +  memset(zTempPath, 0, SQLITE_WIN32_MAX_PATH+2);
  3889   3899   
  3890   3900     if( sqlite3_temp_directory ){
  3891         -    sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
         3901  +    sqlite3_snprintf(SQLITE_WIN32_MAX_PATH-30, zTempPath, "%s",
         3902  +                     sqlite3_temp_directory);
  3892   3903     }
  3893   3904   #if !SQLITE_OS_WINRT
  3894   3905     else if( isNT() ){
  3895   3906       char *zMulti;
  3896   3907       WCHAR zWidePath[MAX_PATH];
  3897   3908       osGetTempPathW(MAX_PATH-30, zWidePath);
  3898   3909       zMulti = unicodeToUtf8(zWidePath);
  3899   3910       if( zMulti ){
  3900         -      sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti);
         3911  +      sqlite3_snprintf(SQLITE_WIN32_MAX_PATH-30, zTempPath, "%s", zMulti);
  3901   3912         sqlite3_free(zMulti);
  3902   3913       }else{
  3903   3914         OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  3904   3915         return SQLITE_IOERR_NOMEM;
  3905   3916       }
  3906   3917     }
  3907   3918   #ifdef SQLITE_WIN32_HAS_ANSI
  3908   3919     else{
  3909   3920       char *zUtf8;
  3910         -    char zMbcsPath[MAX_PATH];
  3911         -    osGetTempPathA(MAX_PATH-30, zMbcsPath);
         3921  +    char zMbcsPath[SQLITE_WIN32_MAX_PATH];
         3922  +    osGetTempPathA(SQLITE_WIN32_MAX_PATH-30, zMbcsPath);
  3912   3923       zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
  3913   3924       if( zUtf8 ){
  3914         -      sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8);
         3925  +      sqlite3_snprintf(SQLITE_WIN32_MAX_PATH-30, zTempPath, "%s", zUtf8);
  3915   3926         sqlite3_free(zUtf8);
  3916   3927       }else{
  3917   3928         OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  3918   3929         return SQLITE_IOERR_NOMEM;
  3919   3930       }
  3920   3931     }
  3921   3932   #endif
................................................................................
  4001   4012     void *zConverted;              /* Filename in OS encoding */
  4002   4013     const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
  4003   4014     int cnt = 0;
  4004   4015   
  4005   4016     /* If argument zPath is a NULL pointer, this function is required to open
  4006   4017     ** a temporary file. Use this buffer to store the file name in.
  4007   4018     */
  4008         -  char zTmpname[MAX_PATH+2];     /* Buffer used to create temp filename */
         4019  +  char zTmpname[SQLITE_WIN32_MAX_PATH+2];     /* Buffer used to create temp filename */
  4009   4020   
  4010   4021     int rc = SQLITE_OK;            /* Function Return Code */
  4011   4022   #if !defined(NDEBUG) || SQLITE_OS_WINCE
  4012   4023     int eType = flags&0xFFFFFF00;  /* Type of file to open */
  4013   4024   #endif
  4014   4025   
  4015   4026     int isExclusive  = (flags & SQLITE_OPEN_EXCLUSIVE);
................................................................................
  4067   4078   #endif
  4068   4079   
  4069   4080     /* If the second argument to this function is NULL, generate a 
  4070   4081     ** temporary file name to use 
  4071   4082     */
  4072   4083     if( !zUtf8Name ){
  4073   4084       assert(isDelete && !isOpenJournal);
  4074         -    memset(zTmpname, 0, MAX_PATH+2);
  4075         -    rc = getTempname(MAX_PATH+2, zTmpname);
         4085  +    memset(zTmpname, 0, SQLITE_WIN32_MAX_PATH+2);
         4086  +    rc = getTempname(SQLITE_WIN32_MAX_PATH+2, zTmpname);
  4076   4087       if( rc!=SQLITE_OK ){
  4077   4088         OSTRACE(("OPEN name=%s, rc=%s", zUtf8Name, sqlite3ErrName(rc)));
  4078   4089         return rc;
  4079   4090       }
  4080   4091       zUtf8Name = zTmpname;
  4081   4092     }
  4082   4093   
................................................................................
  4499   4510     int nFull,                    /* Size of output buffer in bytes */
  4500   4511     char *zFull                   /* Output buffer */
  4501   4512   ){
  4502   4513     
  4503   4514   #if defined(__CYGWIN__)
  4504   4515     SimulateIOError( return SQLITE_ERROR );
  4505   4516     UNUSED_PARAMETER(nFull);
  4506         -  assert( pVfs->mxPathname>=MAX_PATH );
         4517  +  assert( pVfs->mxPathname>=SQLITE_WIN32_MAX_PATH );
  4507   4518     assert( nFull>=pVfs->mxPathname );
  4508   4519     if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){
  4509   4520       /*
  4510   4521       ** NOTE: We are dealing with a relative path name and the data
  4511   4522       **       directory has been set.  Therefore, use it as the basis
  4512   4523       **       for converting the relative path name to an absolute
  4513   4524       **       one by prepending the data directory and a slash.
  4514   4525       */
  4515         -    char zOut[MAX_PATH+1];
  4516         -    memset(zOut, 0, MAX_PATH+1);
         4526  +    char zOut[SQLITE_WIN32_MAX_PATH+1];
         4527  +    memset(zOut, 0, SQLITE_WIN32_MAX_PATH+1);
  4517   4528       cygwin_conv_path(CCP_POSIX_TO_WIN_A|CCP_RELATIVE, zRelative, zOut,
  4518         -                     MAX_PATH+1);
         4529  +                     SQLITE_WIN32_MAX_PATH+1);
  4519   4530       sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s\\%s",
  4520   4531                        sqlite3_data_directory, zOut);
  4521   4532     }else{
  4522   4533       cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull);
  4523   4534     }
  4524   4535     return SQLITE_OK;
  4525   4536   #endif
................................................................................
  4857   4868   /*
  4858   4869   ** Initialize and deinitialize the operating system interface.
  4859   4870   */
  4860   4871   int sqlite3_os_init(void){
  4861   4872     static sqlite3_vfs winVfs = {
  4862   4873       3,                   /* iVersion */
  4863   4874       sizeof(winFile),     /* szOsFile */
  4864         -    MAX_PATH,            /* mxPathname */
         4875  +    SQLITE_WIN32_MAX_PATH, /* mxPathname */
  4865   4876       0,                   /* pNext */
  4866   4877       "win32",             /* zName */
  4867   4878       0,                   /* pAppData */
  4868   4879       winOpen,             /* xOpen */
  4869   4880       winDelete,           /* xDelete */
  4870   4881       winAccess,           /* xAccess */
  4871   4882       winFullPathname,     /* xFullPathname */