Fossil SCM

Fix the file_relative_name() function so that it works on windows.

drh 2011-08-14 23:12 UTC ben-testing
Commit 47b5bf7d166505182d64aa8469be9c4c154ee5a6
1 file changed +23 -4
+23 -4
--- src/file.c
+++ src/file.c
@@ -499,26 +499,45 @@
499499
}
500500
}
501501
}
502502
return 1;
503503
}
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
+}
504515
505516
/*
506517
** Compute a pathname for a file or directory that is relative
507518
** to the current directory.
508519
*/
509520
void file_relative_name(const char *zOrigName, Blob *pOut){
510521
char *zPath;
511522
blob_set(pOut, zOrigName);
512523
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));
514525
if( zPath[0]=='/' ){
515526
int i, j;
516527
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
520539
if( zPath[i]==0 ){
521540
blob_reset(pOut);
522541
if( zPwd[i]==0 ){
523542
blob_append(pOut, ".", 1);
524543
}else{
525544
--- 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

Keyboard Shortcuts

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