libidav/utils.c

changeset 818
bc782cca0759
parent 816
839fefbdedc7
equal deleted inserted replaced
817:22257f6d06a3 818:bc782cca0759
520 520
521 size_t max = path_len > base_len ? base_len : path_len; 521 size_t max = path_len > base_len ? base_len : path_len;
522 522
523 // get prefix of abspath and base 523 // get prefix of abspath and base
524 // this dir is the root of the link 524 // this dir is the root of the link
525 size_t i;
526 size_t last_dir = 0; 525 size_t last_dir = 0;
527 for(i=0;i<max;i++) { 526 for(size_t i=0;i<max;i++) {
528 char c = abspath[i]; 527 char c = abspath[i];
529 if(c != base[i]) { 528 if(c != base[i]) {
530 break; 529 break;
531 } else if(IS_PATH_SEPARATOR(c)) { 530 } else if(IS_PATH_SEPARATOR(c)) {
532 last_dir = i; 531 last_dir = i;
535 534
536 char *ret = NULL; 535 char *ret = NULL;
537 CxBuffer out; 536 CxBuffer out;
538 if(last_dir+1 < base_len) { 537 if(last_dir+1 < base_len) {
539 // base is deeper than the link root, we have to go backwards 538 // base is deeper than the link root, we have to go backwards
540 int dircount = 0; 539 size_t dircount = 0;
541 for(int i=last_dir+1;i<base_len;i++) { 540 for(size_t i=last_dir+1;i<base_len;i++) {
542 if(IS_PATH_SEPARATOR(base[i])) { 541 if(IS_PATH_SEPARATOR(base[i])) {
543 dircount++; 542 dircount++;
544 } 543 }
545 } 544 }
546 545
547 cxBufferInit(&out, NULL, dircount*3+path_len-last_dir, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 546 cxBufferInit(&out, NULL, dircount*3+path_len-last_dir, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
548 547
549 for(int i=0;i<dircount;i++) { 548 for(size_t i=0;i<dircount;i++) {
550 cxBufferPutString(&out, "../"); 549 cxBufferPutString(&out, "../");
551 } 550 }
552 } else { 551 } else {
553 cxBufferInit(&out, NULL, path_len - last_dir, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 552 cxBufferInit(&out, NULL, path_len - last_dir, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
554 } 553 }

mercurial