Fossil SCM
Further improvements to fossil_temp_filename() to help ensure that the correct directory separators are used on both unix and windows.
Commit
5434d2e32ce5f19cbca8980dc6d5fb012074f7f6a21904f2a92b59291d9cf471
Parent
939696667aacc23…
1 file changed
+9
-1
+9
-1
| --- src/util.c | ||
| +++ src/util.c | ||
| @@ -649,10 +649,13 @@ | ||
| 649 | 649 | ** freed by the caller. |
| 650 | 650 | */ |
| 651 | 651 | char *fossil_temp_filename(void){ |
| 652 | 652 | char *zTFile = 0; |
| 653 | 653 | const char *zDir; |
| 654 | + char cDirSep; | |
| 655 | + char zSep[2]; | |
| 656 | + size_t nDir; | |
| 654 | 657 | u64 r[2]; |
| 655 | 658 | int i; |
| 656 | 659 | #ifdef _WIN32 |
| 657 | 660 | char zTempDir[1000]; |
| 658 | 661 | #else |
| @@ -663,10 +666,11 @@ | ||
| 663 | 666 | if( zTFile ) return zTFile; |
| 664 | 667 | } |
| 665 | 668 | sqlite3_randomness(sizeof(r), &r); |
| 666 | 669 | #if _WIN32 |
| 667 | 670 | zTempDir[0] = 0; |
| 671 | + cDirSep = '\\'; | |
| 668 | 672 | GetTempPathA(sizeof(zTempDir), zTempDir); |
| 669 | 673 | if( zTempDir[0] ){ |
| 670 | 674 | zDir = zTempDir; |
| 671 | 675 | }else{ |
| 672 | 676 | zDir = fossil_getenv("LOCALAPPDATA"); |
| @@ -679,12 +683,16 @@ | ||
| 679 | 683 | if( stat(zDir,&buf)==0 && S_ISDIR(buf.st_mode) && access(zDir,03)==0 ){ |
| 680 | 684 | break; |
| 681 | 685 | } |
| 682 | 686 | } |
| 683 | 687 | if( i>=sizeof(azTmp)/sizeof(azTmp[0]) ) zDir = "."; |
| 688 | + cDirSep = '/'; | |
| 684 | 689 | #endif |
| 685 | - return sqlite3_mprintf("%s/fossil%016llx%016llx", zDir, r[0], r[1]); | |
| 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]); | |
| 686 | 694 | } |
| 687 | 695 | |
| 688 | 696 | /* |
| 689 | 697 | ** Turn memory limits for stack and heap on and off. The argument |
| 690 | 698 | ** is true to turn memory limits on and false to turn them off. |
| 691 | 699 |
| --- src/util.c | |
| +++ src/util.c | |
| @@ -649,10 +649,13 @@ | |
| 649 | ** freed by the caller. |
| 650 | */ |
| 651 | char *fossil_temp_filename(void){ |
| 652 | char *zTFile = 0; |
| 653 | const char *zDir; |
| 654 | u64 r[2]; |
| 655 | int i; |
| 656 | #ifdef _WIN32 |
| 657 | char zTempDir[1000]; |
| 658 | #else |
| @@ -663,10 +666,11 @@ | |
| 663 | if( zTFile ) return zTFile; |
| 664 | } |
| 665 | sqlite3_randomness(sizeof(r), &r); |
| 666 | #if _WIN32 |
| 667 | zTempDir[0] = 0; |
| 668 | GetTempPathA(sizeof(zTempDir), zTempDir); |
| 669 | if( zTempDir[0] ){ |
| 670 | zDir = zTempDir; |
| 671 | }else{ |
| 672 | zDir = fossil_getenv("LOCALAPPDATA"); |
| @@ -679,12 +683,16 @@ | |
| 679 | if( stat(zDir,&buf)==0 && S_ISDIR(buf.st_mode) && access(zDir,03)==0 ){ |
| 680 | break; |
| 681 | } |
| 682 | } |
| 683 | if( i>=sizeof(azTmp)/sizeof(azTmp[0]) ) zDir = "."; |
| 684 | #endif |
| 685 | return sqlite3_mprintf("%s/fossil%016llx%016llx", zDir, r[0], r[1]); |
| 686 | } |
| 687 | |
| 688 | /* |
| 689 | ** Turn memory limits for stack and heap on and off. The argument |
| 690 | ** is true to turn memory limits on and false to turn them off. |
| 691 |
| --- src/util.c | |
| +++ src/util.c | |
| @@ -649,10 +649,13 @@ | |
| 649 | ** freed by the caller. |
| 650 | */ |
| 651 | char *fossil_temp_filename(void){ |
| 652 | char *zTFile = 0; |
| 653 | const char *zDir; |
| 654 | char cDirSep; |
| 655 | char zSep[2]; |
| 656 | size_t nDir; |
| 657 | u64 r[2]; |
| 658 | int i; |
| 659 | #ifdef _WIN32 |
| 660 | char zTempDir[1000]; |
| 661 | #else |
| @@ -663,10 +666,11 @@ | |
| 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"); |
| @@ -679,12 +683,16 @@ | |
| 683 | if( stat(zDir,&buf)==0 && S_ISDIR(buf.st_mode) && access(zDir,03)==0 ){ |
| 684 | break; |
| 685 | } |
| 686 | } |
| 687 | if( i>=sizeof(azTmp)/sizeof(azTmp[0]) ) zDir = "."; |
| 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 |