Fossil SCM
Fix the file_relative_name() function so that it works on windows.
Commit
47b5bf7d166505182d64aa8469be9c4c154ee5a6
Parent
3113f7b18f672ee…
1 file changed
+23
-4
+23
-4
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -499,26 +499,45 @@ | ||
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | } |
| 502 | 502 | return 1; |
| 503 | 503 | } |
| 504 | + | |
| 505 | +/* | |
| 506 | +** Return a pointer to the first character in a pathname past the | |
| 507 | +** drive letter. This routine is a no-op on unix. | |
| 508 | +*/ | |
| 509 | +char *file_without_drive_letter(char *zIn){ | |
| 510 | +#ifdef _WIN32 | |
| 511 | + if( fossil_isalpha(zIn[0]) && zIn[1]==':' ) zIn += 2; | |
| 512 | +#endif | |
| 513 | + return zIn; | |
| 514 | +} | |
| 504 | 515 | |
| 505 | 516 | /* |
| 506 | 517 | ** Compute a pathname for a file or directory that is relative |
| 507 | 518 | ** to the current directory. |
| 508 | 519 | */ |
| 509 | 520 | void file_relative_name(const char *zOrigName, Blob *pOut){ |
| 510 | 521 | char *zPath; |
| 511 | 522 | blob_set(pOut, zOrigName); |
| 512 | 523 | blob_resize(pOut, file_simplify_name(blob_buffer(pOut), blob_size(pOut))); |
| 513 | - zPath = blob_buffer(pOut); | |
| 524 | + zPath = file_without_drive_letter(blob_buffer(pOut)); | |
| 514 | 525 | if( zPath[0]=='/' ){ |
| 515 | 526 | int i, j; |
| 516 | 527 | Blob tmp; |
| 517 | - char zPwd[2000]; | |
| 518 | - file_getcwd(zPwd, sizeof(zPwd)-20); | |
| 519 | - for(i=1; zPath[i] && zPwd[i]==zPath[i]; i++){} | |
| 528 | + char *zPwd; | |
| 529 | + char zBuf[2000]; | |
| 530 | + zPwd = zBuf; | |
| 531 | + file_getcwd(zBuf, sizeof(zBuf)-20); | |
| 532 | + zPwd = file_without_drive_letter(zBuf); | |
| 533 | + i = 1; | |
| 534 | +#ifdef _WIN32 | |
| 535 | + while( zPath[i] && fossil_tolower(zPwd[i])==fossil_tolower(zPath[i]) ) i++; | |
| 536 | +#else | |
| 537 | + while( zPath[i] && zPwd[i]==zPath[i] ) i++; | |
| 538 | +#endif | |
| 520 | 539 | if( zPath[i]==0 ){ |
| 521 | 540 | blob_reset(pOut); |
| 522 | 541 | if( zPwd[i]==0 ){ |
| 523 | 542 | blob_append(pOut, ".", 1); |
| 524 | 543 | }else{ |
| 525 | 544 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -499,26 +499,45 @@ | |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | return 1; |
| 503 | } |
| 504 | |
| 505 | /* |
| 506 | ** Compute a pathname for a file or directory that is relative |
| 507 | ** to the current directory. |
| 508 | */ |
| 509 | void file_relative_name(const char *zOrigName, Blob *pOut){ |
| 510 | char *zPath; |
| 511 | blob_set(pOut, zOrigName); |
| 512 | blob_resize(pOut, file_simplify_name(blob_buffer(pOut), blob_size(pOut))); |
| 513 | zPath = blob_buffer(pOut); |
| 514 | if( zPath[0]=='/' ){ |
| 515 | int i, j; |
| 516 | Blob tmp; |
| 517 | char zPwd[2000]; |
| 518 | file_getcwd(zPwd, sizeof(zPwd)-20); |
| 519 | for(i=1; zPath[i] && zPwd[i]==zPath[i]; i++){} |
| 520 | if( zPath[i]==0 ){ |
| 521 | blob_reset(pOut); |
| 522 | if( zPwd[i]==0 ){ |
| 523 | blob_append(pOut, ".", 1); |
| 524 | }else{ |
| 525 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -499,26 +499,45 @@ | |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | return 1; |
| 503 | } |
| 504 | |
| 505 | /* |
| 506 | ** Return a pointer to the first character in a pathname past the |
| 507 | ** drive letter. This routine is a no-op on unix. |
| 508 | */ |
| 509 | char *file_without_drive_letter(char *zIn){ |
| 510 | #ifdef _WIN32 |
| 511 | if( fossil_isalpha(zIn[0]) && zIn[1]==':' ) zIn += 2; |
| 512 | #endif |
| 513 | return zIn; |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | ** Compute a pathname for a file or directory that is relative |
| 518 | ** to the current directory. |
| 519 | */ |
| 520 | void file_relative_name(const char *zOrigName, Blob *pOut){ |
| 521 | char *zPath; |
| 522 | blob_set(pOut, zOrigName); |
| 523 | blob_resize(pOut, file_simplify_name(blob_buffer(pOut), blob_size(pOut))); |
| 524 | zPath = file_without_drive_letter(blob_buffer(pOut)); |
| 525 | if( zPath[0]=='/' ){ |
| 526 | int i, j; |
| 527 | Blob tmp; |
| 528 | char *zPwd; |
| 529 | char zBuf[2000]; |
| 530 | zPwd = zBuf; |
| 531 | file_getcwd(zBuf, sizeof(zBuf)-20); |
| 532 | zPwd = file_without_drive_letter(zBuf); |
| 533 | i = 1; |
| 534 | #ifdef _WIN32 |
| 535 | while( zPath[i] && fossil_tolower(zPwd[i])==fossil_tolower(zPath[i]) ) i++; |
| 536 | #else |
| 537 | while( zPath[i] && zPwd[i]==zPath[i] ) i++; |
| 538 | #endif |
| 539 | if( zPath[i]==0 ){ |
| 540 | blob_reset(pOut); |
| 541 | if( zPwd[i]==0 ){ |
| 542 | blob_append(pOut, ".", 1); |
| 543 | }else{ |
| 544 |