Fossil SCM

On Windows, deal with the reserved 12 characters (8.3) always needed for long directory names.

drh 2015-12-03 22:53 trunk merge
Commit 9571b68a7aea9dc6561cf55c5bf8adf58c044d58
+1 -1
--- src/checkin.c
+++ src/checkin.c
@@ -926,11 +926,11 @@
926926
}
927927
#if defined(_WIN32) || defined(__CYGWIN__)
928928
if( zEditor==0 ){
929929
zEditor = mprintf("%s\\notepad.exe", fossil_getenv("SYSTEMROOT"));
930930
#if defined(__CYGWIN__)
931
- zEditor = fossil_utf8_to_filename(zEditor);
931
+ zEditor = fossil_utf8_to_path(zEditor, 0);
932932
blob_add_cr(pPrompt);
933933
#endif
934934
}
935935
#endif
936936
if( zEditor==0 ){
937937
--- src/checkin.c
+++ src/checkin.c
@@ -926,11 +926,11 @@
926 }
927 #if defined(_WIN32) || defined(__CYGWIN__)
928 if( zEditor==0 ){
929 zEditor = mprintf("%s\\notepad.exe", fossil_getenv("SYSTEMROOT"));
930 #if defined(__CYGWIN__)
931 zEditor = fossil_utf8_to_filename(zEditor);
932 blob_add_cr(pPrompt);
933 #endif
934 }
935 #endif
936 if( zEditor==0 ){
937
--- src/checkin.c
+++ src/checkin.c
@@ -926,11 +926,11 @@
926 }
927 #if defined(_WIN32) || defined(__CYGWIN__)
928 if( zEditor==0 ){
929 zEditor = mprintf("%s\\notepad.exe", fossil_getenv("SYSTEMROOT"));
930 #if defined(__CYGWIN__)
931 zEditor = fossil_utf8_to_path(zEditor, 0);
932 blob_add_cr(pPrompt);
933 #endif
934 }
935 #endif
936 if( zEditor==0 ){
937
+26 -26
--- src/file.c
+++ src/file.c
@@ -86,21 +86,21 @@
8686
** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
8787
**
8888
*/
8989
static int fossil_stat(const char *zFilename, struct fossilStat *buf, int isWd){
9090
int rc;
91
- void *zMbcs = fossil_utf8_to_filename(zFilename);
91
+ void *zMbcs = fossil_utf8_to_path(zFilename, 0);
9292
#if !defined(_WIN32)
9393
if( isWd && g.allowSymlinks ){
9494
rc = lstat(zMbcs, buf);
9595
}else{
9696
rc = stat(zMbcs, buf);
9797
}
9898
#else
9999
rc = win32_stat(zMbcs, buf, isWd);
100100
#endif
101
- fossil_filename_free(zMbcs);
101
+ fossil_path_free(zMbcs);
102102
return rc;
103103
}
104104
105105
/*
106106
** Fill in the fileStat variable for the file named zFilename.
@@ -314,17 +314,17 @@
314314
/*
315315
** Wrapper around the access() system call.
316316
*/
317317
int file_access(const char *zFilename, int flags){
318318
int rc;
319
- void *zMbcs = fossil_utf8_to_filename(zFilename);
319
+ void *zMbcs = fossil_utf8_to_path(zFilename, 0);
320320
#ifdef _WIN32
321321
rc = win32_access(zMbcs, flags);
322322
#else
323323
rc = access(zMbcs, flags);
324324
#endif
325
- fossil_filename_free(zMbcs);
325
+ fossil_path_free(zMbcs);
326326
return rc;
327327
}
328328
329329
/*
330330
** Wrapper around the chdir() system call.
@@ -331,21 +331,21 @@
331331
** If bChroot=1, do a chroot to this dir as well
332332
** (UNIX only)
333333
*/
334334
int file_chdir(const char *zChDir, int bChroot){
335335
int rc;
336
- void *zPath = fossil_utf8_to_filename(zChDir);
336
+ void *zPath = fossil_utf8_to_path(zChDir, 1);
337337
#ifdef _WIN32
338338
rc = win32_chdir(zPath, bChroot);
339339
#else
340340
rc = chdir(zPath);
341341
if( !rc && bChroot ){
342342
rc = chroot(zPath);
343343
if( !rc ) rc = chdir("/");
344344
}
345345
#endif
346
- fossil_filename_free(zPath);
346
+ fossil_path_free(zPath);
347347
return rc;
348348
}
349349
350350
/*
351351
** Find an unused filename similar to zBase with zSuffix appended.
@@ -469,20 +469,20 @@
469469
char *zMbcs;
470470
struct timeval tv[2];
471471
memset(tv, 0, sizeof(tv[0])*2);
472472
tv[0].tv_sec = newMTime;
473473
tv[1].tv_sec = newMTime;
474
- zMbcs = fossil_utf8_to_filename(zFilename);
474
+ zMbcs = fossil_utf8_to_path(zFilename, 0);
475475
utimes(zMbcs, tv);
476476
#else
477477
struct _utimbuf tb;
478
- wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
478
+ wchar_t *zMbcs = fossil_utf8_to_path(zFilename, 0);
479479
tb.actime = newMTime;
480480
tb.modtime = newMTime;
481481
_wutime(zMbcs, &tb);
482482
#endif
483
- fossil_filename_free(zMbcs);
483
+ fossil_path_free(zMbcs);
484484
}
485485
486486
/*
487487
** COMMAND: test-set-mtime
488488
**
@@ -512,17 +512,17 @@
512512
** Returns zero upon success.
513513
*/
514514
int file_delete(const char *zFilename){
515515
int rc;
516516
#ifdef _WIN32
517
- wchar_t *z = fossil_utf8_to_filename(zFilename);
517
+ wchar_t *z = fossil_utf8_to_path(zFilename, 0);
518518
rc = _wunlink(z);
519519
#else
520
- char *z = fossil_utf8_to_filename(zFilename);
520
+ char *z = fossil_utf8_to_path(zFilename, 0);
521521
rc = unlink(zFilename);
522522
#endif
523
- fossil_filename_free(z);
523
+ fossil_path_free(z);
524524
return rc;
525525
}
526526
527527
/*
528528
** Create the directory named in the argument, if it does not already
@@ -537,17 +537,17 @@
537537
if( !forceFlag ) return 1;
538538
file_delete(zName);
539539
}
540540
if( rc!=1 ){
541541
#if defined(_WIN32)
542
- wchar_t *zMbcs = fossil_utf8_to_filename(zName);
542
+ wchar_t *zMbcs = fossil_utf8_to_path(zName, 1);
543543
rc = _wmkdir(zMbcs);
544544
#else
545
- char *zMbcs = fossil_utf8_to_filename(zName);
545
+ char *zMbcs = fossil_utf8_to_path(zName, 1);
546546
rc = mkdir(zName, 0755);
547547
#endif
548
- fossil_filename_free(zMbcs);
548
+ fossil_path_free(zMbcs);
549549
return rc;
550550
}
551551
return 0;
552552
}
553553
@@ -602,17 +602,17 @@
602602
int file_rmdir(const char *zName){
603603
int rc = file_wd_isdir(zName);
604604
if( rc==2 ) return 1; /* cannot remove normal file */
605605
if( rc==1 ){
606606
#if defined(_WIN32)
607
- wchar_t *zMbcs = fossil_utf8_to_filename(zName);
607
+ wchar_t *zMbcs = fossil_utf8_to_path(zName, 1);
608608
rc = _wrmdir(zMbcs);
609609
#else
610
- char *zMbcs = fossil_utf8_to_filename(zName);
610
+ char *zMbcs = fossil_utf8_to_path(zName, 1);
611611
rc = rmdir(zName);
612612
#endif
613
- fossil_filename_free(zMbcs);
613
+ fossil_path_free(zMbcs);
614614
return rc;
615615
}
616616
return 0;
617617
}
618618
@@ -1243,11 +1243,11 @@
12431243
12441244
#if defined(_WIN32)
12451245
wchar_t zTmpPath[MAX_PATH];
12461246
12471247
if( GetTempPathW(MAX_PATH, zTmpPath) ){
1248
- azDirs[0] = fossil_filename_to_utf8(zTmpPath);
1248
+ azDirs[0] = fossil_path_to_utf8(zTmpPath);
12491249
}
12501250
12511251
azDirs[1] = fossil_getenv("TEMP");
12521252
azDirs[2] = fossil_getenv("TMP");
12531253
#endif
@@ -1277,13 +1277,13 @@
12771277
}
12781278
zBuf[j] = 0;
12791279
}while( file_size(zBuf)>=0 );
12801280
12811281
#if defined(_WIN32)
1282
- fossil_filename_free((char *)azDirs[0]);
1283
- fossil_filename_free((char *)azDirs[1]);
1284
- fossil_filename_free((char *)azDirs[2]);
1282
+ fossil_path_free((char *)azDirs[0]);
1283
+ fossil_path_free((char *)azDirs[1]);
1284
+ fossil_path_free((char *)azDirs[2]);
12851285
#endif
12861286
}
12871287
12881288
12891289
/*
@@ -1309,21 +1309,21 @@
13091309
return rc==0;
13101310
}
13111311
13121312
/*
13131313
** Return the value of an environment variable as UTF8.
1314
-** Use fossil_filename_free() to release resources.
1314
+** Use fossil_path_free() to release resources.
13151315
*/
13161316
char *fossil_getenv(const char *zName){
13171317
#ifdef _WIN32
13181318
wchar_t *uName = fossil_utf8_to_unicode(zName);
13191319
void *zValue = _wgetenv(uName);
13201320
fossil_unicode_free(uName);
13211321
#else
13221322
char *zValue = getenv(zName);
13231323
#endif
1324
- if( zValue ) zValue = fossil_filename_to_utf8(zValue);
1324
+ if( zValue ) zValue = fossil_path_to_utf8(zValue);
13251325
return zValue;
13261326
}
13271327
13281328
/*
13291329
** Sets the value of an environment variable as UTF8.
@@ -1348,14 +1348,14 @@
13481348
** Like fopen() but always takes a UTF8 argument.
13491349
*/
13501350
FILE *fossil_fopen(const char *zName, const char *zMode){
13511351
#ifdef _WIN32
13521352
wchar_t *uMode = fossil_utf8_to_unicode(zMode);
1353
- wchar_t *uName = fossil_utf8_to_filename(zName);
1353
+ wchar_t *uName = fossil_utf8_to_path(zName, 0);
13541354
FILE *f = _wfopen(uName, uMode);
1355
- fossil_filename_free(uName);
1355
+ fossil_path_free(uName);
13561356
fossil_unicode_free(uMode);
13571357
#else
13581358
FILE *f = fopen(zName, zMode);
13591359
#endif
13601360
return f;
13611361
}
13621362
--- src/file.c
+++ src/file.c
@@ -86,21 +86,21 @@
86 ** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
87 **
88 */
89 static int fossil_stat(const char *zFilename, struct fossilStat *buf, int isWd){
90 int rc;
91 void *zMbcs = fossil_utf8_to_filename(zFilename);
92 #if !defined(_WIN32)
93 if( isWd && g.allowSymlinks ){
94 rc = lstat(zMbcs, buf);
95 }else{
96 rc = stat(zMbcs, buf);
97 }
98 #else
99 rc = win32_stat(zMbcs, buf, isWd);
100 #endif
101 fossil_filename_free(zMbcs);
102 return rc;
103 }
104
105 /*
106 ** Fill in the fileStat variable for the file named zFilename.
@@ -314,17 +314,17 @@
314 /*
315 ** Wrapper around the access() system call.
316 */
317 int file_access(const char *zFilename, int flags){
318 int rc;
319 void *zMbcs = fossil_utf8_to_filename(zFilename);
320 #ifdef _WIN32
321 rc = win32_access(zMbcs, flags);
322 #else
323 rc = access(zMbcs, flags);
324 #endif
325 fossil_filename_free(zMbcs);
326 return rc;
327 }
328
329 /*
330 ** Wrapper around the chdir() system call.
@@ -331,21 +331,21 @@
331 ** If bChroot=1, do a chroot to this dir as well
332 ** (UNIX only)
333 */
334 int file_chdir(const char *zChDir, int bChroot){
335 int rc;
336 void *zPath = fossil_utf8_to_filename(zChDir);
337 #ifdef _WIN32
338 rc = win32_chdir(zPath, bChroot);
339 #else
340 rc = chdir(zPath);
341 if( !rc && bChroot ){
342 rc = chroot(zPath);
343 if( !rc ) rc = chdir("/");
344 }
345 #endif
346 fossil_filename_free(zPath);
347 return rc;
348 }
349
350 /*
351 ** Find an unused filename similar to zBase with zSuffix appended.
@@ -469,20 +469,20 @@
469 char *zMbcs;
470 struct timeval tv[2];
471 memset(tv, 0, sizeof(tv[0])*2);
472 tv[0].tv_sec = newMTime;
473 tv[1].tv_sec = newMTime;
474 zMbcs = fossil_utf8_to_filename(zFilename);
475 utimes(zMbcs, tv);
476 #else
477 struct _utimbuf tb;
478 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
479 tb.actime = newMTime;
480 tb.modtime = newMTime;
481 _wutime(zMbcs, &tb);
482 #endif
483 fossil_filename_free(zMbcs);
484 }
485
486 /*
487 ** COMMAND: test-set-mtime
488 **
@@ -512,17 +512,17 @@
512 ** Returns zero upon success.
513 */
514 int file_delete(const char *zFilename){
515 int rc;
516 #ifdef _WIN32
517 wchar_t *z = fossil_utf8_to_filename(zFilename);
518 rc = _wunlink(z);
519 #else
520 char *z = fossil_utf8_to_filename(zFilename);
521 rc = unlink(zFilename);
522 #endif
523 fossil_filename_free(z);
524 return rc;
525 }
526
527 /*
528 ** Create the directory named in the argument, if it does not already
@@ -537,17 +537,17 @@
537 if( !forceFlag ) return 1;
538 file_delete(zName);
539 }
540 if( rc!=1 ){
541 #if defined(_WIN32)
542 wchar_t *zMbcs = fossil_utf8_to_filename(zName);
543 rc = _wmkdir(zMbcs);
544 #else
545 char *zMbcs = fossil_utf8_to_filename(zName);
546 rc = mkdir(zName, 0755);
547 #endif
548 fossil_filename_free(zMbcs);
549 return rc;
550 }
551 return 0;
552 }
553
@@ -602,17 +602,17 @@
602 int file_rmdir(const char *zName){
603 int rc = file_wd_isdir(zName);
604 if( rc==2 ) return 1; /* cannot remove normal file */
605 if( rc==1 ){
606 #if defined(_WIN32)
607 wchar_t *zMbcs = fossil_utf8_to_filename(zName);
608 rc = _wrmdir(zMbcs);
609 #else
610 char *zMbcs = fossil_utf8_to_filename(zName);
611 rc = rmdir(zName);
612 #endif
613 fossil_filename_free(zMbcs);
614 return rc;
615 }
616 return 0;
617 }
618
@@ -1243,11 +1243,11 @@
1243
1244 #if defined(_WIN32)
1245 wchar_t zTmpPath[MAX_PATH];
1246
1247 if( GetTempPathW(MAX_PATH, zTmpPath) ){
1248 azDirs[0] = fossil_filename_to_utf8(zTmpPath);
1249 }
1250
1251 azDirs[1] = fossil_getenv("TEMP");
1252 azDirs[2] = fossil_getenv("TMP");
1253 #endif
@@ -1277,13 +1277,13 @@
1277 }
1278 zBuf[j] = 0;
1279 }while( file_size(zBuf)>=0 );
1280
1281 #if defined(_WIN32)
1282 fossil_filename_free((char *)azDirs[0]);
1283 fossil_filename_free((char *)azDirs[1]);
1284 fossil_filename_free((char *)azDirs[2]);
1285 #endif
1286 }
1287
1288
1289 /*
@@ -1309,21 +1309,21 @@
1309 return rc==0;
1310 }
1311
1312 /*
1313 ** Return the value of an environment variable as UTF8.
1314 ** Use fossil_filename_free() to release resources.
1315 */
1316 char *fossil_getenv(const char *zName){
1317 #ifdef _WIN32
1318 wchar_t *uName = fossil_utf8_to_unicode(zName);
1319 void *zValue = _wgetenv(uName);
1320 fossil_unicode_free(uName);
1321 #else
1322 char *zValue = getenv(zName);
1323 #endif
1324 if( zValue ) zValue = fossil_filename_to_utf8(zValue);
1325 return zValue;
1326 }
1327
1328 /*
1329 ** Sets the value of an environment variable as UTF8.
@@ -1348,14 +1348,14 @@
1348 ** Like fopen() but always takes a UTF8 argument.
1349 */
1350 FILE *fossil_fopen(const char *zName, const char *zMode){
1351 #ifdef _WIN32
1352 wchar_t *uMode = fossil_utf8_to_unicode(zMode);
1353 wchar_t *uName = fossil_utf8_to_filename(zName);
1354 FILE *f = _wfopen(uName, uMode);
1355 fossil_filename_free(uName);
1356 fossil_unicode_free(uMode);
1357 #else
1358 FILE *f = fopen(zName, zMode);
1359 #endif
1360 return f;
1361 }
1362
--- src/file.c
+++ src/file.c
@@ -86,21 +86,21 @@
86 ** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
87 **
88 */
89 static int fossil_stat(const char *zFilename, struct fossilStat *buf, int isWd){
90 int rc;
91 void *zMbcs = fossil_utf8_to_path(zFilename, 0);
92 #if !defined(_WIN32)
93 if( isWd && g.allowSymlinks ){
94 rc = lstat(zMbcs, buf);
95 }else{
96 rc = stat(zMbcs, buf);
97 }
98 #else
99 rc = win32_stat(zMbcs, buf, isWd);
100 #endif
101 fossil_path_free(zMbcs);
102 return rc;
103 }
104
105 /*
106 ** Fill in the fileStat variable for the file named zFilename.
@@ -314,17 +314,17 @@
314 /*
315 ** Wrapper around the access() system call.
316 */
317 int file_access(const char *zFilename, int flags){
318 int rc;
319 void *zMbcs = fossil_utf8_to_path(zFilename, 0);
320 #ifdef _WIN32
321 rc = win32_access(zMbcs, flags);
322 #else
323 rc = access(zMbcs, flags);
324 #endif
325 fossil_path_free(zMbcs);
326 return rc;
327 }
328
329 /*
330 ** Wrapper around the chdir() system call.
@@ -331,21 +331,21 @@
331 ** If bChroot=1, do a chroot to this dir as well
332 ** (UNIX only)
333 */
334 int file_chdir(const char *zChDir, int bChroot){
335 int rc;
336 void *zPath = fossil_utf8_to_path(zChDir, 1);
337 #ifdef _WIN32
338 rc = win32_chdir(zPath, bChroot);
339 #else
340 rc = chdir(zPath);
341 if( !rc && bChroot ){
342 rc = chroot(zPath);
343 if( !rc ) rc = chdir("/");
344 }
345 #endif
346 fossil_path_free(zPath);
347 return rc;
348 }
349
350 /*
351 ** Find an unused filename similar to zBase with zSuffix appended.
@@ -469,20 +469,20 @@
469 char *zMbcs;
470 struct timeval tv[2];
471 memset(tv, 0, sizeof(tv[0])*2);
472 tv[0].tv_sec = newMTime;
473 tv[1].tv_sec = newMTime;
474 zMbcs = fossil_utf8_to_path(zFilename, 0);
475 utimes(zMbcs, tv);
476 #else
477 struct _utimbuf tb;
478 wchar_t *zMbcs = fossil_utf8_to_path(zFilename, 0);
479 tb.actime = newMTime;
480 tb.modtime = newMTime;
481 _wutime(zMbcs, &tb);
482 #endif
483 fossil_path_free(zMbcs);
484 }
485
486 /*
487 ** COMMAND: test-set-mtime
488 **
@@ -512,17 +512,17 @@
512 ** Returns zero upon success.
513 */
514 int file_delete(const char *zFilename){
515 int rc;
516 #ifdef _WIN32
517 wchar_t *z = fossil_utf8_to_path(zFilename, 0);
518 rc = _wunlink(z);
519 #else
520 char *z = fossil_utf8_to_path(zFilename, 0);
521 rc = unlink(zFilename);
522 #endif
523 fossil_path_free(z);
524 return rc;
525 }
526
527 /*
528 ** Create the directory named in the argument, if it does not already
@@ -537,17 +537,17 @@
537 if( !forceFlag ) return 1;
538 file_delete(zName);
539 }
540 if( rc!=1 ){
541 #if defined(_WIN32)
542 wchar_t *zMbcs = fossil_utf8_to_path(zName, 1);
543 rc = _wmkdir(zMbcs);
544 #else
545 char *zMbcs = fossil_utf8_to_path(zName, 1);
546 rc = mkdir(zName, 0755);
547 #endif
548 fossil_path_free(zMbcs);
549 return rc;
550 }
551 return 0;
552 }
553
@@ -602,17 +602,17 @@
602 int file_rmdir(const char *zName){
603 int rc = file_wd_isdir(zName);
604 if( rc==2 ) return 1; /* cannot remove normal file */
605 if( rc==1 ){
606 #if defined(_WIN32)
607 wchar_t *zMbcs = fossil_utf8_to_path(zName, 1);
608 rc = _wrmdir(zMbcs);
609 #else
610 char *zMbcs = fossil_utf8_to_path(zName, 1);
611 rc = rmdir(zName);
612 #endif
613 fossil_path_free(zMbcs);
614 return rc;
615 }
616 return 0;
617 }
618
@@ -1243,11 +1243,11 @@
1243
1244 #if defined(_WIN32)
1245 wchar_t zTmpPath[MAX_PATH];
1246
1247 if( GetTempPathW(MAX_PATH, zTmpPath) ){
1248 azDirs[0] = fossil_path_to_utf8(zTmpPath);
1249 }
1250
1251 azDirs[1] = fossil_getenv("TEMP");
1252 azDirs[2] = fossil_getenv("TMP");
1253 #endif
@@ -1277,13 +1277,13 @@
1277 }
1278 zBuf[j] = 0;
1279 }while( file_size(zBuf)>=0 );
1280
1281 #if defined(_WIN32)
1282 fossil_path_free((char *)azDirs[0]);
1283 fossil_path_free((char *)azDirs[1]);
1284 fossil_path_free((char *)azDirs[2]);
1285 #endif
1286 }
1287
1288
1289 /*
@@ -1309,21 +1309,21 @@
1309 return rc==0;
1310 }
1311
1312 /*
1313 ** Return the value of an environment variable as UTF8.
1314 ** Use fossil_path_free() to release resources.
1315 */
1316 char *fossil_getenv(const char *zName){
1317 #ifdef _WIN32
1318 wchar_t *uName = fossil_utf8_to_unicode(zName);
1319 void *zValue = _wgetenv(uName);
1320 fossil_unicode_free(uName);
1321 #else
1322 char *zValue = getenv(zName);
1323 #endif
1324 if( zValue ) zValue = fossil_path_to_utf8(zValue);
1325 return zValue;
1326 }
1327
1328 /*
1329 ** Sets the value of an environment variable as UTF8.
@@ -1348,14 +1348,14 @@
1348 ** Like fopen() but always takes a UTF8 argument.
1349 */
1350 FILE *fossil_fopen(const char *zName, const char *zMode){
1351 #ifdef _WIN32
1352 wchar_t *uMode = fossil_utf8_to_unicode(zMode);
1353 wchar_t *uName = fossil_utf8_to_path(zName, 0);
1354 FILE *f = _wfopen(uName, uMode);
1355 fossil_path_free(uName);
1356 fossil_unicode_free(uMode);
1357 #else
1358 FILE *f = fopen(zName, zMode);
1359 #endif
1360 return f;
1361 }
1362
+3 -3
--- src/main.c
+++ src/main.c
@@ -420,15 +420,15 @@
420420
g.argv = argv;
421421
sqlite3_initialize();
422422
#if defined(_WIN32) && defined(BROKEN_MINGW_CMDLINE)
423423
for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
424424
#else
425
- for(i=0; i<g.argc; i++) g.argv[i] = fossil_filename_to_utf8(g.argv[i]);
425
+ for(i=0; i<g.argc; i++) g.argv[i] = fossil_path_to_utf8(g.argv[i]);
426426
#endif
427427
#if defined(_WIN32)
428428
GetModuleFileNameW(NULL, buf, MAX_PATH);
429
- g.nameOfExe = fossil_filename_to_utf8(buf);
429
+ g.nameOfExe = fossil_path_to_utf8(buf);
430430
#else
431431
g.nameOfExe = g.argv[0];
432432
#endif
433433
for(i=1; i<g.argc-1; i++){
434434
z = g.argv[i];
@@ -2546,11 +2546,11 @@
25462546
**
25472547
** Echo all command-line arguments (enclosed in [...]) to the screen so that
25482548
** wildcard expansion behavior of the host shell can be investigated.
25492549
**
25502550
** With the --hex option, show the output as hexadecimal. This can be used
2551
-** to verify the fossil_filename_to_utf8() routine on Windows and Mac.
2551
+** to verify the fossil_path_to_utf8() routine on Windows and Mac.
25522552
*/
25532553
void test_echo_cmd(void){
25542554
int i, j;
25552555
if( find_option("hex",0,0)==0 ){
25562556
fossil_print("g.nameOfExe = [%s]\n", g.nameOfExe);
25572557
--- src/main.c
+++ src/main.c
@@ -420,15 +420,15 @@
420 g.argv = argv;
421 sqlite3_initialize();
422 #if defined(_WIN32) && defined(BROKEN_MINGW_CMDLINE)
423 for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
424 #else
425 for(i=0; i<g.argc; i++) g.argv[i] = fossil_filename_to_utf8(g.argv[i]);
426 #endif
427 #if defined(_WIN32)
428 GetModuleFileNameW(NULL, buf, MAX_PATH);
429 g.nameOfExe = fossil_filename_to_utf8(buf);
430 #else
431 g.nameOfExe = g.argv[0];
432 #endif
433 for(i=1; i<g.argc-1; i++){
434 z = g.argv[i];
@@ -2546,11 +2546,11 @@
2546 **
2547 ** Echo all command-line arguments (enclosed in [...]) to the screen so that
2548 ** wildcard expansion behavior of the host shell can be investigated.
2549 **
2550 ** With the --hex option, show the output as hexadecimal. This can be used
2551 ** to verify the fossil_filename_to_utf8() routine on Windows and Mac.
2552 */
2553 void test_echo_cmd(void){
2554 int i, j;
2555 if( find_option("hex",0,0)==0 ){
2556 fossil_print("g.nameOfExe = [%s]\n", g.nameOfExe);
2557
--- src/main.c
+++ src/main.c
@@ -420,15 +420,15 @@
420 g.argv = argv;
421 sqlite3_initialize();
422 #if defined(_WIN32) && defined(BROKEN_MINGW_CMDLINE)
423 for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
424 #else
425 for(i=0; i<g.argc; i++) g.argv[i] = fossil_path_to_utf8(g.argv[i]);
426 #endif
427 #if defined(_WIN32)
428 GetModuleFileNameW(NULL, buf, MAX_PATH);
429 g.nameOfExe = fossil_path_to_utf8(buf);
430 #else
431 g.nameOfExe = g.argv[0];
432 #endif
433 for(i=1; i<g.argc-1; i++){
434 z = g.argv[i];
@@ -2546,11 +2546,11 @@
2546 **
2547 ** Echo all command-line arguments (enclosed in [...]) to the screen so that
2548 ** wildcard expansion behavior of the host shell can be investigated.
2549 **
2550 ** With the --hex option, show the output as hexadecimal. This can be used
2551 ** to verify the fossil_path_to_utf8() routine on Windows and Mac.
2552 */
2553 void test_echo_cmd(void){
2554 int i, j;
2555 if( find_option("hex",0,0)==0 ){
2556 fossil_print("g.nameOfExe = [%s]\n", g.nameOfExe);
2557
+1 -1
--- src/printf.c
+++ src/printf.c
@@ -982,11 +982,11 @@
982982
va_end(ap);
983983
for(i=0; i<sizeof(azEnv)/sizeof(azEnv[0]); i++){
984984
char *p;
985985
if( (p = fossil_getenv(azEnv[i]))!=0 ){
986986
fprintf(out, "%s=%s\n", azEnv[i], p);
987
- fossil_filename_free(p);
987
+ fossil_path_free(p);
988988
}else if( (z = P(azEnv[i]))!=0 ){
989989
fprintf(out, "%s=%s\n", azEnv[i], z);
990990
}
991991
}
992992
fclose(out);
993993
--- src/printf.c
+++ src/printf.c
@@ -982,11 +982,11 @@
982 va_end(ap);
983 for(i=0; i<sizeof(azEnv)/sizeof(azEnv[0]); i++){
984 char *p;
985 if( (p = fossil_getenv(azEnv[i]))!=0 ){
986 fprintf(out, "%s=%s\n", azEnv[i], p);
987 fossil_filename_free(p);
988 }else if( (z = P(azEnv[i]))!=0 ){
989 fprintf(out, "%s=%s\n", azEnv[i], z);
990 }
991 }
992 fclose(out);
993
--- src/printf.c
+++ src/printf.c
@@ -982,11 +982,11 @@
982 va_end(ap);
983 for(i=0; i<sizeof(azEnv)/sizeof(azEnv[0]); i++){
984 char *p;
985 if( (p = fossil_getenv(azEnv[i]))!=0 ){
986 fprintf(out, "%s=%s\n", azEnv[i], p);
987 fossil_path_free(p);
988 }else if( (z = P(azEnv[i]))!=0 ){
989 fprintf(out, "%s=%s\n", azEnv[i], z);
990 }
991 }
992 fclose(out);
993
+4 -4
--- src/rebuild.c
+++ src/rebuild.c
@@ -887,23 +887,23 @@
887887
Blob aContent; /* content of the just read artifact */
888888
static int nFileRead = 0;
889889
void *zUnicodePath;
890890
char *zUtf8Name;
891891
892
- zUnicodePath = fossil_utf8_to_filename(zPath);
892
+ zUnicodePath = fossil_utf8_to_path(zPath, 1);
893893
d = opendir(zUnicodePath);
894894
if( d ){
895895
while( (pEntry=readdir(d))!=0 ){
896896
Blob path;
897897
char *zSubpath;
898898
899899
if( pEntry->d_name[0]=='.' ){
900900
continue;
901901
}
902
- zUtf8Name = fossil_filename_to_utf8(pEntry->d_name);
902
+ zUtf8Name = fossil_path_to_utf8(pEntry->d_name);
903903
zSubpath = mprintf("%s/%s", zPath, zUtf8Name);
904
- fossil_filename_free(zUtf8Name);
904
+ fossil_path_free(zUtf8Name);
905905
#ifdef _DIRENT_HAVE_D_TYPE
906906
if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
907907
? (file_isdir(zSubpath)==1) : (pEntry->d_type==DT_DIR) )
908908
#else
909909
if( file_isdir(zSubpath)==1 )
@@ -928,11 +928,11 @@
928928
closedir(d);
929929
}else {
930930
fossil_fatal("encountered error %d while trying to open \"%s\".",
931931
errno, g.argv[3]);
932932
}
933
- fossil_filename_free(zUnicodePath);
933
+ fossil_path_free(zUnicodePath);
934934
}
935935
936936
/*
937937
** COMMAND: reconstruct*
938938
**
939939
--- src/rebuild.c
+++ src/rebuild.c
@@ -887,23 +887,23 @@
887 Blob aContent; /* content of the just read artifact */
888 static int nFileRead = 0;
889 void *zUnicodePath;
890 char *zUtf8Name;
891
892 zUnicodePath = fossil_utf8_to_filename(zPath);
893 d = opendir(zUnicodePath);
894 if( d ){
895 while( (pEntry=readdir(d))!=0 ){
896 Blob path;
897 char *zSubpath;
898
899 if( pEntry->d_name[0]=='.' ){
900 continue;
901 }
902 zUtf8Name = fossil_filename_to_utf8(pEntry->d_name);
903 zSubpath = mprintf("%s/%s", zPath, zUtf8Name);
904 fossil_filename_free(zUtf8Name);
905 #ifdef _DIRENT_HAVE_D_TYPE
906 if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
907 ? (file_isdir(zSubpath)==1) : (pEntry->d_type==DT_DIR) )
908 #else
909 if( file_isdir(zSubpath)==1 )
@@ -928,11 +928,11 @@
928 closedir(d);
929 }else {
930 fossil_fatal("encountered error %d while trying to open \"%s\".",
931 errno, g.argv[3]);
932 }
933 fossil_filename_free(zUnicodePath);
934 }
935
936 /*
937 ** COMMAND: reconstruct*
938 **
939
--- src/rebuild.c
+++ src/rebuild.c
@@ -887,23 +887,23 @@
887 Blob aContent; /* content of the just read artifact */
888 static int nFileRead = 0;
889 void *zUnicodePath;
890 char *zUtf8Name;
891
892 zUnicodePath = fossil_utf8_to_path(zPath, 1);
893 d = opendir(zUnicodePath);
894 if( d ){
895 while( (pEntry=readdir(d))!=0 ){
896 Blob path;
897 char *zSubpath;
898
899 if( pEntry->d_name[0]=='.' ){
900 continue;
901 }
902 zUtf8Name = fossil_path_to_utf8(pEntry->d_name);
903 zSubpath = mprintf("%s/%s", zPath, zUtf8Name);
904 fossil_path_free(zUtf8Name);
905 #ifdef _DIRENT_HAVE_D_TYPE
906 if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
907 ? (file_isdir(zSubpath)==1) : (pEntry->d_type==DT_DIR) )
908 #else
909 if( file_isdir(zSubpath)==1 )
@@ -928,11 +928,11 @@
928 closedir(d);
929 }else {
930 fossil_fatal("encountered error %d while trying to open \"%s\".",
931 errno, g.argv[3]);
932 }
933 fossil_path_free(zUnicodePath);
934 }
935
936 /*
937 ** COMMAND: reconstruct*
938 **
939
+15 -14
--- src/utf8.c
+++ src/utf8.c
@@ -101,11 +101,11 @@
101101
#endif
102102
103103
/*
104104
** Translate text from the filename character set into UTF-8.
105105
** Return a pointer to the translated text.
106
-** Call fossil_filename_free() to deallocate any memory used to store the
106
+** Call fossil_path_free() to deallocate any memory used to store the
107107
** returned pointer when done.
108108
**
109109
** This function must not convert '\' to '/' on windows/cygwin, as it is
110110
** used in places where we are not sure it's really filenames we are handling,
111111
** e.g. fossil_getenv() or handling the argv arguments from main().
@@ -113,19 +113,19 @@
113113
** On Windows, translate some characters in the in the range
114114
** U+F001 - U+F07F (private use area) to ASCII. Cygwin sometimes
115115
** generates such filenames. See:
116116
** <http://cygwin.com/cygwin-ug-net/using-specialnames.html>
117117
*/
118
-char *fossil_filename_to_utf8(const void *zFilename){
118
+char *fossil_path_to_utf8(const void *zPath){
119119
#if defined(_WIN32)
120
- int nByte = WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, 0, 0, 0, 0);
120
+ int nByte = WideCharToMultiByte(CP_UTF8, 0, zPath, -1, 0, 0, 0, 0);
121121
char *zUtf = sqlite3_malloc( nByte );
122122
char *pUtf, *qUtf;
123123
if( zUtf==0 ){
124124
return 0;
125125
}
126
- WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, zUtf, nByte, 0, 0);
126
+ WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zUtf, nByte, 0, 0);
127127
pUtf = qUtf = zUtf;
128128
while( *pUtf ) {
129129
if( *pUtf == (char)0xef ){
130130
wchar_t c = ((pUtf[1]&0x3f)<<6)|(pUtf[2]&0x3f);
131131
/* Only really convert it when the resulting char is in range. */
@@ -137,14 +137,14 @@
137137
}
138138
*qUtf = 0;
139139
return zUtf;
140140
#elif defined(__CYGWIN__)
141141
char *zOut;
142
- zOut = fossil_strdup(zFilename);
142
+ zOut = fossil_strdup(zPath);
143143
return zOut;
144144
#elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
145
- char *zIn = (char*)zFilename;
145
+ char *zIn = (char*)zPath;
146146
char *zOut;
147147
iconv_t cd;
148148
size_t n, x;
149149
for(n=0; zIn[n]>0 && zIn[n]<=0x7f; n++){}
150150
if( zIn[n]!=0 && (cd = iconv_open("UTF-8", "UTF-8-MAC"))!=(iconv_t)-1 ){
@@ -161,22 +161,22 @@
161161
}else{
162162
zOut[n+100-nOutx] = 0;
163163
}
164164
iconv_close(cd);
165165
}else{
166
- zOut = fossil_strdup(zFilename);
166
+ zOut = fossil_strdup(zPath);
167167
}
168168
return zOut;
169169
#else
170
- return (char *)zFilename; /* No-op on non-mac unix */
170
+ return (char *)zPath; /* No-op on non-mac unix */
171171
#endif
172172
}
173173
174174
/*
175175
** Translate text from UTF-8 to the filename character set.
176176
** Return a pointer to the translated text.
177
-** Call fossil_filename_free() to deallocate any memory used to store the
177
+** Call fossil_path_free() to deallocate any memory used to store the
178178
** returned pointer when done.
179179
**
180180
** On Windows, characters in the range U+0001 to U+0031 and the
181181
** characters '"', '*', ':', '<', '>', '?' and '|' are invalid
182182
** to be used, except in the 'extended path' prefix ('?') and
@@ -187,12 +187,13 @@
187187
** everything looks as expected.
188188
**
189189
** See: <http://cygwin.com/cygwin-ug-net/using-specialnames.html>
190190
**
191191
*/
192
-void *fossil_utf8_to_filename(const char *zUtf8){
192
+void *fossil_utf8_to_path(const char *zUtf8, int isDir){
193193
#ifdef _WIN32
194
+ int nReserved = isDir ? 12 : 0; /* For dir, need room for "FILENAME.EXT" */
194195
int nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
195196
/* Overallocate 6 chars, making some room for extended paths */
196197
wchar_t *zUnicode = sqlite3_malloc( (nChar+6) * sizeof(wchar_t) );
197198
wchar_t *wUnicode = zUnicode;
198199
if( zUnicode==0 ){
@@ -216,11 +217,11 @@
216217
** prefixed with the extended path prefix. See:
217218
** <http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#maxpath>
218219
**/
219220
if( fossil_isalpha(zUtf8[0]) && zUtf8[1]==':'
220221
&& (zUtf8[2]=='\\' || zUtf8[2]=='/') ){
221
- if( wUnicode==zUnicode && nChar>MAX_PATH){
222
+ if( wUnicode==zUnicode && (nChar-nReserved)>MAX_PATH){
222223
memmove(wUnicode+4, wUnicode, nChar*sizeof(wchar_t));
223224
memcpy(wUnicode, L"\\\\?\\", 4*sizeof(wchar_t));
224225
wUnicode += 4;
225226
}
226227
/*
@@ -227,11 +228,11 @@
227228
** If (remainder of) path starts with "<drive>:/" or "<drive>:\",
228229
** leave the ':' intact but translate the backslash to a slash.
229230
*/
230231
wUnicode[2] = '\\';
231232
wUnicode += 3;
232
- }else if( wUnicode==zUnicode && nChar>MAX_PATH
233
+ }else if( wUnicode==zUnicode && (nChar-nReserved)>MAX_PATH
233234
&& (zUtf8[0]=='\\' || zUtf8[0]=='/')
234235
&& (zUtf8[1]=='\\' || zUtf8[1]=='/') && zUtf8[2]!='?'){
235236
memmove(wUnicode+6, wUnicode, nChar*sizeof(wchar_t));
236237
memcpy(wUnicode, L"\\\\?\\UNC", 7*sizeof(wchar_t));
237238
wUnicode += 7;
@@ -286,13 +287,13 @@
286287
#endif
287288
}
288289
289290
/*
290291
** Deallocate any memory that was previously allocated by
291
-** fossil_filename_to_utf8() or fossil_utf8_to_filename().
292
+** fossil_path_to_utf8() or fossil_utf8_to_path().
292293
*/
293
-void fossil_filename_free(void *pOld){
294
+void fossil_path_free(void *pOld){
294295
#if defined(_WIN32)
295296
sqlite3_free(pOld);
296297
#elif (defined(__APPLE__) && !defined(WITHOUT_ICONV)) || defined(__CYGWIN__)
297298
fossil_free(pOld);
298299
#else
299300
--- src/utf8.c
+++ src/utf8.c
@@ -101,11 +101,11 @@
101 #endif
102
103 /*
104 ** Translate text from the filename character set into UTF-8.
105 ** Return a pointer to the translated text.
106 ** Call fossil_filename_free() to deallocate any memory used to store the
107 ** returned pointer when done.
108 **
109 ** This function must not convert '\' to '/' on windows/cygwin, as it is
110 ** used in places where we are not sure it's really filenames we are handling,
111 ** e.g. fossil_getenv() or handling the argv arguments from main().
@@ -113,19 +113,19 @@
113 ** On Windows, translate some characters in the in the range
114 ** U+F001 - U+F07F (private use area) to ASCII. Cygwin sometimes
115 ** generates such filenames. See:
116 ** <http://cygwin.com/cygwin-ug-net/using-specialnames.html>
117 */
118 char *fossil_filename_to_utf8(const void *zFilename){
119 #if defined(_WIN32)
120 int nByte = WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, 0, 0, 0, 0);
121 char *zUtf = sqlite3_malloc( nByte );
122 char *pUtf, *qUtf;
123 if( zUtf==0 ){
124 return 0;
125 }
126 WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, zUtf, nByte, 0, 0);
127 pUtf = qUtf = zUtf;
128 while( *pUtf ) {
129 if( *pUtf == (char)0xef ){
130 wchar_t c = ((pUtf[1]&0x3f)<<6)|(pUtf[2]&0x3f);
131 /* Only really convert it when the resulting char is in range. */
@@ -137,14 +137,14 @@
137 }
138 *qUtf = 0;
139 return zUtf;
140 #elif defined(__CYGWIN__)
141 char *zOut;
142 zOut = fossil_strdup(zFilename);
143 return zOut;
144 #elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
145 char *zIn = (char*)zFilename;
146 char *zOut;
147 iconv_t cd;
148 size_t n, x;
149 for(n=0; zIn[n]>0 && zIn[n]<=0x7f; n++){}
150 if( zIn[n]!=0 && (cd = iconv_open("UTF-8", "UTF-8-MAC"))!=(iconv_t)-1 ){
@@ -161,22 +161,22 @@
161 }else{
162 zOut[n+100-nOutx] = 0;
163 }
164 iconv_close(cd);
165 }else{
166 zOut = fossil_strdup(zFilename);
167 }
168 return zOut;
169 #else
170 return (char *)zFilename; /* No-op on non-mac unix */
171 #endif
172 }
173
174 /*
175 ** Translate text from UTF-8 to the filename character set.
176 ** Return a pointer to the translated text.
177 ** Call fossil_filename_free() to deallocate any memory used to store the
178 ** returned pointer when done.
179 **
180 ** On Windows, characters in the range U+0001 to U+0031 and the
181 ** characters '"', '*', ':', '<', '>', '?' and '|' are invalid
182 ** to be used, except in the 'extended path' prefix ('?') and
@@ -187,12 +187,13 @@
187 ** everything looks as expected.
188 **
189 ** See: <http://cygwin.com/cygwin-ug-net/using-specialnames.html>
190 **
191 */
192 void *fossil_utf8_to_filename(const char *zUtf8){
193 #ifdef _WIN32
 
194 int nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
195 /* Overallocate 6 chars, making some room for extended paths */
196 wchar_t *zUnicode = sqlite3_malloc( (nChar+6) * sizeof(wchar_t) );
197 wchar_t *wUnicode = zUnicode;
198 if( zUnicode==0 ){
@@ -216,11 +217,11 @@
216 ** prefixed with the extended path prefix. See:
217 ** <http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#maxpath>
218 **/
219 if( fossil_isalpha(zUtf8[0]) && zUtf8[1]==':'
220 && (zUtf8[2]=='\\' || zUtf8[2]=='/') ){
221 if( wUnicode==zUnicode && nChar>MAX_PATH){
222 memmove(wUnicode+4, wUnicode, nChar*sizeof(wchar_t));
223 memcpy(wUnicode, L"\\\\?\\", 4*sizeof(wchar_t));
224 wUnicode += 4;
225 }
226 /*
@@ -227,11 +228,11 @@
227 ** If (remainder of) path starts with "<drive>:/" or "<drive>:\",
228 ** leave the ':' intact but translate the backslash to a slash.
229 */
230 wUnicode[2] = '\\';
231 wUnicode += 3;
232 }else if( wUnicode==zUnicode && nChar>MAX_PATH
233 && (zUtf8[0]=='\\' || zUtf8[0]=='/')
234 && (zUtf8[1]=='\\' || zUtf8[1]=='/') && zUtf8[2]!='?'){
235 memmove(wUnicode+6, wUnicode, nChar*sizeof(wchar_t));
236 memcpy(wUnicode, L"\\\\?\\UNC", 7*sizeof(wchar_t));
237 wUnicode += 7;
@@ -286,13 +287,13 @@
286 #endif
287 }
288
289 /*
290 ** Deallocate any memory that was previously allocated by
291 ** fossil_filename_to_utf8() or fossil_utf8_to_filename().
292 */
293 void fossil_filename_free(void *pOld){
294 #if defined(_WIN32)
295 sqlite3_free(pOld);
296 #elif (defined(__APPLE__) && !defined(WITHOUT_ICONV)) || defined(__CYGWIN__)
297 fossil_free(pOld);
298 #else
299
--- src/utf8.c
+++ src/utf8.c
@@ -101,11 +101,11 @@
101 #endif
102
103 /*
104 ** Translate text from the filename character set into UTF-8.
105 ** Return a pointer to the translated text.
106 ** Call fossil_path_free() to deallocate any memory used to store the
107 ** returned pointer when done.
108 **
109 ** This function must not convert '\' to '/' on windows/cygwin, as it is
110 ** used in places where we are not sure it's really filenames we are handling,
111 ** e.g. fossil_getenv() or handling the argv arguments from main().
@@ -113,19 +113,19 @@
113 ** On Windows, translate some characters in the in the range
114 ** U+F001 - U+F07F (private use area) to ASCII. Cygwin sometimes
115 ** generates such filenames. See:
116 ** <http://cygwin.com/cygwin-ug-net/using-specialnames.html>
117 */
118 char *fossil_path_to_utf8(const void *zPath){
119 #if defined(_WIN32)
120 int nByte = WideCharToMultiByte(CP_UTF8, 0, zPath, -1, 0, 0, 0, 0);
121 char *zUtf = sqlite3_malloc( nByte );
122 char *pUtf, *qUtf;
123 if( zUtf==0 ){
124 return 0;
125 }
126 WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zUtf, nByte, 0, 0);
127 pUtf = qUtf = zUtf;
128 while( *pUtf ) {
129 if( *pUtf == (char)0xef ){
130 wchar_t c = ((pUtf[1]&0x3f)<<6)|(pUtf[2]&0x3f);
131 /* Only really convert it when the resulting char is in range. */
@@ -137,14 +137,14 @@
137 }
138 *qUtf = 0;
139 return zUtf;
140 #elif defined(__CYGWIN__)
141 char *zOut;
142 zOut = fossil_strdup(zPath);
143 return zOut;
144 #elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
145 char *zIn = (char*)zPath;
146 char *zOut;
147 iconv_t cd;
148 size_t n, x;
149 for(n=0; zIn[n]>0 && zIn[n]<=0x7f; n++){}
150 if( zIn[n]!=0 && (cd = iconv_open("UTF-8", "UTF-8-MAC"))!=(iconv_t)-1 ){
@@ -161,22 +161,22 @@
161 }else{
162 zOut[n+100-nOutx] = 0;
163 }
164 iconv_close(cd);
165 }else{
166 zOut = fossil_strdup(zPath);
167 }
168 return zOut;
169 #else
170 return (char *)zPath; /* No-op on non-mac unix */
171 #endif
172 }
173
174 /*
175 ** Translate text from UTF-8 to the filename character set.
176 ** Return a pointer to the translated text.
177 ** Call fossil_path_free() to deallocate any memory used to store the
178 ** returned pointer when done.
179 **
180 ** On Windows, characters in the range U+0001 to U+0031 and the
181 ** characters '"', '*', ':', '<', '>', '?' and '|' are invalid
182 ** to be used, except in the 'extended path' prefix ('?') and
@@ -187,12 +187,13 @@
187 ** everything looks as expected.
188 **
189 ** See: <http://cygwin.com/cygwin-ug-net/using-specialnames.html>
190 **
191 */
192 void *fossil_utf8_to_path(const char *zUtf8, int isDir){
193 #ifdef _WIN32
194 int nReserved = isDir ? 12 : 0; /* For dir, need room for "FILENAME.EXT" */
195 int nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
196 /* Overallocate 6 chars, making some room for extended paths */
197 wchar_t *zUnicode = sqlite3_malloc( (nChar+6) * sizeof(wchar_t) );
198 wchar_t *wUnicode = zUnicode;
199 if( zUnicode==0 ){
@@ -216,11 +217,11 @@
217 ** prefixed with the extended path prefix. See:
218 ** <http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#maxpath>
219 **/
220 if( fossil_isalpha(zUtf8[0]) && zUtf8[1]==':'
221 && (zUtf8[2]=='\\' || zUtf8[2]=='/') ){
222 if( wUnicode==zUnicode && (nChar-nReserved)>MAX_PATH){
223 memmove(wUnicode+4, wUnicode, nChar*sizeof(wchar_t));
224 memcpy(wUnicode, L"\\\\?\\", 4*sizeof(wchar_t));
225 wUnicode += 4;
226 }
227 /*
@@ -227,11 +228,11 @@
228 ** If (remainder of) path starts with "<drive>:/" or "<drive>:\",
229 ** leave the ':' intact but translate the backslash to a slash.
230 */
231 wUnicode[2] = '\\';
232 wUnicode += 3;
233 }else if( wUnicode==zUnicode && (nChar-nReserved)>MAX_PATH
234 && (zUtf8[0]=='\\' || zUtf8[0]=='/')
235 && (zUtf8[1]=='\\' || zUtf8[1]=='/') && zUtf8[2]!='?'){
236 memmove(wUnicode+6, wUnicode, nChar*sizeof(wchar_t));
237 memcpy(wUnicode, L"\\\\?\\UNC", 7*sizeof(wchar_t));
238 wUnicode += 7;
@@ -286,13 +287,13 @@
287 #endif
288 }
289
290 /*
291 ** Deallocate any memory that was previously allocated by
292 ** fossil_path_to_utf8() or fossil_utf8_to_path().
293 */
294 void fossil_path_free(void *pOld){
295 #if defined(_WIN32)
296 sqlite3_free(pOld);
297 #elif (defined(__APPLE__) && !defined(WITHOUT_ICONV)) || defined(__CYGWIN__)
298 fossil_free(pOld);
299 #else
300
+8 -8
--- src/vfile.c
+++ src/vfile.c
@@ -501,11 +501,11 @@
501501
" pathname=:file %s)", filename_collation()
502502
);
503503
}
504504
depth++;
505505
506
- zNative = fossil_utf8_to_filename(blob_str(pPath));
506
+ zNative = fossil_utf8_to_path(blob_str(pPath), 1);
507507
d = opendir(zNative);
508508
if( d ){
509509
while( (pEntry=readdir(d))!=0 ){
510510
char *zPath;
511511
char *zUtf8;
@@ -512,11 +512,11 @@
512512
if( pEntry->d_name[0]=='.' ){
513513
if( (scanFlags & SCAN_ALL)==0 ) continue;
514514
if( pEntry->d_name[1]==0 ) continue;
515515
if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
516516
}
517
- zUtf8 = fossil_filename_to_utf8(pEntry->d_name);
517
+ zUtf8 = fossil_path_to_utf8(pEntry->d_name);
518518
blob_appendf(pPath, "/%s", zUtf8);
519519
zPath = blob_str(pPath);
520520
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
521521
glob_match(pIgnore2, &zPath[nPrefix+1]) ){
522522
/* do nothing */
@@ -539,16 +539,16 @@
539539
db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
540540
db_step(&ins);
541541
db_reset(&ins);
542542
}
543543
}
544
- fossil_filename_free(zUtf8);
544
+ fossil_path_free(zUtf8);
545545
blob_resize(pPath, origSize);
546546
}
547547
closedir(d);
548548
}
549
- fossil_filename_free(zNative);
549
+ fossil_path_free(zNative);
550550
551551
depth--;
552552
if( depth==0 ){
553553
db_finalize(&ins);
554554
}
@@ -613,11 +613,11 @@
613613
filename_collation()
614614
);
615615
}
616616
depth++;
617617
618
- zNative = fossil_utf8_to_filename(blob_str(pPath));
618
+ zNative = fossil_utf8_to_path(blob_str(pPath), 1);
619619
d = opendir(zNative);
620620
if( d ){
621621
while( (pEntry=readdir(d))!=0 ){
622622
char *zOrigPath;
623623
char *zPath;
@@ -626,11 +626,11 @@
626626
if( (scanFlags & SCAN_ALL)==0 ) continue;
627627
if( pEntry->d_name[1]==0 ) continue;
628628
if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
629629
}
630630
zOrigPath = mprintf("%s", blob_str(pPath));
631
- zUtf8 = fossil_filename_to_utf8(pEntry->d_name);
631
+ zUtf8 = fossil_path_to_utf8(pEntry->d_name);
632632
blob_appendf(pPath, "/%s", zUtf8);
633633
zPath = blob_str(pPath);
634634
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
635635
glob_match(pIgnore2, &zPath[nPrefix+1]) ){
636636
/* do nothing */
@@ -660,17 +660,17 @@
660660
db_bind_text(&upd, ":file", zOrigPath);
661661
db_step(&upd);
662662
db_reset(&upd);
663663
result++; /* found 1 normal file */
664664
}
665
- fossil_filename_free(zUtf8);
665
+ fossil_path_free(zUtf8);
666666
blob_resize(pPath, origSize);
667667
fossil_free(zOrigPath);
668668
}
669669
closedir(d);
670670
}
671
- fossil_filename_free(zNative);
671
+ fossil_path_free(zNative);
672672
673673
depth--;
674674
if( depth==0 ){
675675
db_finalize(&upd);
676676
db_finalize(&ins);
677677
--- src/vfile.c
+++ src/vfile.c
@@ -501,11 +501,11 @@
501 " pathname=:file %s)", filename_collation()
502 );
503 }
504 depth++;
505
506 zNative = fossil_utf8_to_filename(blob_str(pPath));
507 d = opendir(zNative);
508 if( d ){
509 while( (pEntry=readdir(d))!=0 ){
510 char *zPath;
511 char *zUtf8;
@@ -512,11 +512,11 @@
512 if( pEntry->d_name[0]=='.' ){
513 if( (scanFlags & SCAN_ALL)==0 ) continue;
514 if( pEntry->d_name[1]==0 ) continue;
515 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
516 }
517 zUtf8 = fossil_filename_to_utf8(pEntry->d_name);
518 blob_appendf(pPath, "/%s", zUtf8);
519 zPath = blob_str(pPath);
520 if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
521 glob_match(pIgnore2, &zPath[nPrefix+1]) ){
522 /* do nothing */
@@ -539,16 +539,16 @@
539 db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
540 db_step(&ins);
541 db_reset(&ins);
542 }
543 }
544 fossil_filename_free(zUtf8);
545 blob_resize(pPath, origSize);
546 }
547 closedir(d);
548 }
549 fossil_filename_free(zNative);
550
551 depth--;
552 if( depth==0 ){
553 db_finalize(&ins);
554 }
@@ -613,11 +613,11 @@
613 filename_collation()
614 );
615 }
616 depth++;
617
618 zNative = fossil_utf8_to_filename(blob_str(pPath));
619 d = opendir(zNative);
620 if( d ){
621 while( (pEntry=readdir(d))!=0 ){
622 char *zOrigPath;
623 char *zPath;
@@ -626,11 +626,11 @@
626 if( (scanFlags & SCAN_ALL)==0 ) continue;
627 if( pEntry->d_name[1]==0 ) continue;
628 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
629 }
630 zOrigPath = mprintf("%s", blob_str(pPath));
631 zUtf8 = fossil_filename_to_utf8(pEntry->d_name);
632 blob_appendf(pPath, "/%s", zUtf8);
633 zPath = blob_str(pPath);
634 if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
635 glob_match(pIgnore2, &zPath[nPrefix+1]) ){
636 /* do nothing */
@@ -660,17 +660,17 @@
660 db_bind_text(&upd, ":file", zOrigPath);
661 db_step(&upd);
662 db_reset(&upd);
663 result++; /* found 1 normal file */
664 }
665 fossil_filename_free(zUtf8);
666 blob_resize(pPath, origSize);
667 fossil_free(zOrigPath);
668 }
669 closedir(d);
670 }
671 fossil_filename_free(zNative);
672
673 depth--;
674 if( depth==0 ){
675 db_finalize(&upd);
676 db_finalize(&ins);
677
--- src/vfile.c
+++ src/vfile.c
@@ -501,11 +501,11 @@
501 " pathname=:file %s)", filename_collation()
502 );
503 }
504 depth++;
505
506 zNative = fossil_utf8_to_path(blob_str(pPath), 1);
507 d = opendir(zNative);
508 if( d ){
509 while( (pEntry=readdir(d))!=0 ){
510 char *zPath;
511 char *zUtf8;
@@ -512,11 +512,11 @@
512 if( pEntry->d_name[0]=='.' ){
513 if( (scanFlags & SCAN_ALL)==0 ) continue;
514 if( pEntry->d_name[1]==0 ) continue;
515 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
516 }
517 zUtf8 = fossil_path_to_utf8(pEntry->d_name);
518 blob_appendf(pPath, "/%s", zUtf8);
519 zPath = blob_str(pPath);
520 if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
521 glob_match(pIgnore2, &zPath[nPrefix+1]) ){
522 /* do nothing */
@@ -539,16 +539,16 @@
539 db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
540 db_step(&ins);
541 db_reset(&ins);
542 }
543 }
544 fossil_path_free(zUtf8);
545 blob_resize(pPath, origSize);
546 }
547 closedir(d);
548 }
549 fossil_path_free(zNative);
550
551 depth--;
552 if( depth==0 ){
553 db_finalize(&ins);
554 }
@@ -613,11 +613,11 @@
613 filename_collation()
614 );
615 }
616 depth++;
617
618 zNative = fossil_utf8_to_path(blob_str(pPath), 1);
619 d = opendir(zNative);
620 if( d ){
621 while( (pEntry=readdir(d))!=0 ){
622 char *zOrigPath;
623 char *zPath;
@@ -626,11 +626,11 @@
626 if( (scanFlags & SCAN_ALL)==0 ) continue;
627 if( pEntry->d_name[1]==0 ) continue;
628 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
629 }
630 zOrigPath = mprintf("%s", blob_str(pPath));
631 zUtf8 = fossil_path_to_utf8(pEntry->d_name);
632 blob_appendf(pPath, "/%s", zUtf8);
633 zPath = blob_str(pPath);
634 if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
635 glob_match(pIgnore2, &zPath[nPrefix+1]) ){
636 /* do nothing */
@@ -660,17 +660,17 @@
660 db_bind_text(&upd, ":file", zOrigPath);
661 db_step(&upd);
662 db_reset(&upd);
663 result++; /* found 1 normal file */
664 }
665 fossil_path_free(zUtf8);
666 blob_resize(pPath, origSize);
667 fossil_free(zOrigPath);
668 }
669 closedir(d);
670 }
671 fossil_path_free(zNative);
672
673 depth--;
674 if( depth==0 ){
675 db_finalize(&upd);
676 db_finalize(&ins);
677
+2 -2
--- src/winfile.c
+++ src/winfile.c
@@ -283,12 +283,12 @@
283283
char *zUtf8;
284284
wchar_t *zWide = fossil_malloc( sizeof(wchar_t)*nBuf );
285285
if( GetCurrentDirectoryW(nBuf, zWide)==0 ){
286286
fossil_fatal("cannot find current working directory.");
287287
}
288
- zUtf8 = fossil_filename_to_utf8(zWide);
288
+ zUtf8 = fossil_path_to_utf8(zWide);
289289
fossil_free(zWide);
290290
for(i=0; zUtf8[i]; i++) if( zUtf8[i]=='\\' ) zUtf8[i] = '/';
291291
strncpy(zBuf, zUtf8, nBuf);
292
- fossil_filename_free(zUtf8);
292
+ fossil_path_free(zUtf8);
293293
}
294294
#endif /* _WIN32 -- This code is for win32 only */
295295
--- src/winfile.c
+++ src/winfile.c
@@ -283,12 +283,12 @@
283 char *zUtf8;
284 wchar_t *zWide = fossil_malloc( sizeof(wchar_t)*nBuf );
285 if( GetCurrentDirectoryW(nBuf, zWide)==0 ){
286 fossil_fatal("cannot find current working directory.");
287 }
288 zUtf8 = fossil_filename_to_utf8(zWide);
289 fossil_free(zWide);
290 for(i=0; zUtf8[i]; i++) if( zUtf8[i]=='\\' ) zUtf8[i] = '/';
291 strncpy(zBuf, zUtf8, nBuf);
292 fossil_filename_free(zUtf8);
293 }
294 #endif /* _WIN32 -- This code is for win32 only */
295
--- src/winfile.c
+++ src/winfile.c
@@ -283,12 +283,12 @@
283 char *zUtf8;
284 wchar_t *zWide = fossil_malloc( sizeof(wchar_t)*nBuf );
285 if( GetCurrentDirectoryW(nBuf, zWide)==0 ){
286 fossil_fatal("cannot find current working directory.");
287 }
288 zUtf8 = fossil_path_to_utf8(zWide);
289 fossil_free(zWide);
290 for(i=0; zUtf8[i]; i++) if( zUtf8[i]=='\\' ) zUtf8[i] = '/';
291 strncpy(zBuf, zUtf8, nBuf);
292 fossil_path_free(zUtf8);
293 }
294 #endif /* _WIN32 -- This code is for win32 only */
295

Keyboard Shortcuts

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