Fossil SCM

On Windows, make sure temporary path names containing non-ASCII characters are accessible, for example if the default temporary path "C:\Users\«Username»\AppData\Local\Temp" contains a user name with extended characters, of if the %TEMP% environment variable points to a directory name with extended characters.

florian 2021-08-31 07:00 trunk
Commit 102339828b4cc518510d7897cfa3b9340135e9dae696ac892237d4da9ecdb76b
3 files changed +9 +1 -1 +13 -6
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -280,13 +280,22 @@
280280
**
281281
** For --browser and --webpage, output the HTML header.
282282
*/
283283
void diff_begin(u64 diffFlags){
284284
if( (diffFlags & DIFF_BROWSER)!=0 ){
285
+#ifdef _WIN32
286
+ LPWSTR tempDiffFilenameW;
287
+#endif
285288
tempDiffFilename = fossil_temp_filename();
286289
tempDiffFilename = sqlite3_mprintf("%z.html", tempDiffFilename);
290
+#ifndef _WIN32
287291
diffOut = freopen(tempDiffFilename,"wb",stdout);
292
+#else
293
+ tempDiffFilenameW = fossil_utf8_to_unicode(tempDiffFilename);
294
+ diffOut = _wfreopen(tempDiffFilenameW,L"wb",stdout);
295
+ fossil_unicode_free(tempDiffFilenameW);
296
+#endif
288297
if( diffOut==0 ){
289298
fossil_fatal("unable to create temporary file \"%s\"",
290299
tempDiffFilename);
291300
}
292301
#ifndef _WIN32
293302
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -280,13 +280,22 @@
280 **
281 ** For --browser and --webpage, output the HTML header.
282 */
283 void diff_begin(u64 diffFlags){
284 if( (diffFlags & DIFF_BROWSER)!=0 ){
 
 
 
285 tempDiffFilename = fossil_temp_filename();
286 tempDiffFilename = sqlite3_mprintf("%z.html", tempDiffFilename);
 
287 diffOut = freopen(tempDiffFilename,"wb",stdout);
 
 
 
 
 
288 if( diffOut==0 ){
289 fossil_fatal("unable to create temporary file \"%s\"",
290 tempDiffFilename);
291 }
292 #ifndef _WIN32
293
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -280,13 +280,22 @@
280 **
281 ** For --browser and --webpage, output the HTML header.
282 */
283 void diff_begin(u64 diffFlags){
284 if( (diffFlags & DIFF_BROWSER)!=0 ){
285 #ifdef _WIN32
286 LPWSTR tempDiffFilenameW;
287 #endif
288 tempDiffFilename = fossil_temp_filename();
289 tempDiffFilename = sqlite3_mprintf("%z.html", tempDiffFilename);
290 #ifndef _WIN32
291 diffOut = freopen(tempDiffFilename,"wb",stdout);
292 #else
293 tempDiffFilenameW = fossil_utf8_to_unicode(tempDiffFilename);
294 diffOut = _wfreopen(tempDiffFilenameW,L"wb",stdout);
295 fossil_unicode_free(tempDiffFilenameW);
296 #endif
297 if( diffOut==0 ){
298 fossil_fatal("unable to create temporary file \"%s\"",
299 tempDiffFilename);
300 }
301 #ifndef _WIN32
302
+1 -1
--- src/utf8.c
+++ src/utf8.c
@@ -88,11 +88,11 @@
8888
#endif
8989
}
9090
9191
/*
9292
** Deallocate any memory that was previously allocated by
93
-** fossil_unicode_to_utf8().
93
+** fossil_unicode_to_utf8() or fossil_utf8_to_unicode().
9494
*/
9595
void fossil_unicode_free(void *pOld){
9696
fossil_free(pOld);
9797
}
9898
9999
--- src/utf8.c
+++ src/utf8.c
@@ -88,11 +88,11 @@
88 #endif
89 }
90
91 /*
92 ** Deallocate any memory that was previously allocated by
93 ** fossil_unicode_to_utf8().
94 */
95 void fossil_unicode_free(void *pOld){
96 fossil_free(pOld);
97 }
98
99
--- src/utf8.c
+++ src/utf8.c
@@ -88,11 +88,11 @@
88 #endif
89 }
90
91 /*
92 ** Deallocate any memory that was previously allocated by
93 ** fossil_unicode_to_utf8() or fossil_utf8_to_unicode().
94 */
95 void fossil_unicode_free(void *pOld){
96 fossil_free(pOld);
97 }
98
99
+13 -6
--- src/util.c
+++ src/util.c
@@ -655,25 +655,28 @@
655655
char zSep[2];
656656
size_t nDir;
657657
u64 r[2];
658658
int i;
659659
#ifdef _WIN32
660
- char zTempDir[1000];
660
+ char *zTempDirA = NULL;
661
+ WCHAR zTempDirW[MAX_PATH+1];
662
+ const DWORD dwTempSizeW = sizeof(zTempDirW)/sizeof(zTempDirW[0]);
663
+ DWORD dwTempLenW;
661664
#else
662665
static const char *azTmp[] = {"/var/tmp","/usr/tmp","/tmp"};
663666
#endif
664667
if( g.db ){
665668
sqlite3_file_control(g.db, 0, SQLITE_FCNTL_TEMPFILENAME, (void*)&zTFile);
666669
if( zTFile ) return zTFile;
667670
}
668671
sqlite3_randomness(sizeof(r), &r);
669672
#if _WIN32
670
- zTempDir[0] = 0;
671673
cDirSep = '\\';
672
- GetTempPathA(sizeof(zTempDir), zTempDir);
673
- if( zTempDir[0] ){
674
- zDir = zTempDir;
674
+ dwTempLenW = GetTempPathW(dwTempSizeW, zTempDirW);
675
+ if( dwTempLenW>0 && dwTempLenW<dwTempSizeW
676
+ && ( zTempDirA = fossil_unicode_to_utf8(zTempDirW) )){
677
+ zDir = zTempDirA;
675678
}else{
676679
zDir = fossil_getenv("LOCALAPPDATA");
677680
if( zDir==0 ) zDir = ".";
678681
}
679682
#else
@@ -688,11 +691,15 @@
688691
cDirSep = '/';
689692
#endif
690693
nDir = strlen(zDir);
691694
zSep[1] = 0;
692695
zSep[0] = (nDir && zDir[nDir-1]==cDirSep) ? 0 : cDirSep;
693
- return sqlite3_mprintf("%s%sfossil%016llx%016llx", zDir,zSep,r[0],r[1]);
696
+ zTFile = sqlite3_mprintf("%s%sfossil%016llx%016llx", zDir,zSep,r[0],r[1]);
697
+#ifdef _WIN32
698
+ if( zTempDirA ) fossil_unicode_free(zTempDirA);
699
+#endif
700
+ return zTFile;
694701
}
695702
696703
/*
697704
** Turn memory limits for stack and heap on and off. The argument
698705
** is true to turn memory limits on and false to turn them off.
699706
--- src/util.c
+++ src/util.c
@@ -655,25 +655,28 @@
655 char zSep[2];
656 size_t nDir;
657 u64 r[2];
658 int i;
659 #ifdef _WIN32
660 char zTempDir[1000];
 
 
 
661 #else
662 static const char *azTmp[] = {"/var/tmp","/usr/tmp","/tmp"};
663 #endif
664 if( g.db ){
665 sqlite3_file_control(g.db, 0, SQLITE_FCNTL_TEMPFILENAME, (void*)&zTFile);
666 if( zTFile ) return zTFile;
667 }
668 sqlite3_randomness(sizeof(r), &r);
669 #if _WIN32
670 zTempDir[0] = 0;
671 cDirSep = '\\';
672 GetTempPathA(sizeof(zTempDir), zTempDir);
673 if( zTempDir[0] ){
674 zDir = zTempDir;
 
675 }else{
676 zDir = fossil_getenv("LOCALAPPDATA");
677 if( zDir==0 ) zDir = ".";
678 }
679 #else
@@ -688,11 +691,15 @@
688 cDirSep = '/';
689 #endif
690 nDir = strlen(zDir);
691 zSep[1] = 0;
692 zSep[0] = (nDir && zDir[nDir-1]==cDirSep) ? 0 : cDirSep;
693 return sqlite3_mprintf("%s%sfossil%016llx%016llx", zDir,zSep,r[0],r[1]);
 
 
 
 
694 }
695
696 /*
697 ** Turn memory limits for stack and heap on and off. The argument
698 ** is true to turn memory limits on and false to turn them off.
699
--- src/util.c
+++ src/util.c
@@ -655,25 +655,28 @@
655 char zSep[2];
656 size_t nDir;
657 u64 r[2];
658 int i;
659 #ifdef _WIN32
660 char *zTempDirA = NULL;
661 WCHAR zTempDirW[MAX_PATH+1];
662 const DWORD dwTempSizeW = sizeof(zTempDirW)/sizeof(zTempDirW[0]);
663 DWORD dwTempLenW;
664 #else
665 static const char *azTmp[] = {"/var/tmp","/usr/tmp","/tmp"};
666 #endif
667 if( g.db ){
668 sqlite3_file_control(g.db, 0, SQLITE_FCNTL_TEMPFILENAME, (void*)&zTFile);
669 if( zTFile ) return zTFile;
670 }
671 sqlite3_randomness(sizeof(r), &r);
672 #if _WIN32
 
673 cDirSep = '\\';
674 dwTempLenW = GetTempPathW(dwTempSizeW, zTempDirW);
675 if( dwTempLenW>0 && dwTempLenW<dwTempSizeW
676 && ( zTempDirA = fossil_unicode_to_utf8(zTempDirW) )){
677 zDir = zTempDirA;
678 }else{
679 zDir = fossil_getenv("LOCALAPPDATA");
680 if( zDir==0 ) zDir = ".";
681 }
682 #else
@@ -688,11 +691,15 @@
691 cDirSep = '/';
692 #endif
693 nDir = strlen(zDir);
694 zSep[1] = 0;
695 zSep[0] = (nDir && zDir[nDir-1]==cDirSep) ? 0 : cDirSep;
696 zTFile = sqlite3_mprintf("%s%sfossil%016llx%016llx", zDir,zSep,r[0],r[1]);
697 #ifdef _WIN32
698 if( zTempDirA ) fossil_unicode_free(zTempDirA);
699 #endif
700 return zTFile;
701 }
702
703 /*
704 ** Turn memory limits for stack and heap on and off. The argument
705 ** is true to turn memory limits on and false to turn them off.
706

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button