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 } |