likle / cwalk

Path library for C/C++. Cross-Platform for Linux, FreeBSD, Windows and MacOS. Supports UNIX and Windows path styles on those platforms.
https://likle.github.io/cwalk/
MIT License
250 stars 39 forks source link

Weird behavior in cwk_path_get_relative when child directory have same name as its parents #23

Closed aomsin2526 closed 3 years ago

aomsin2526 commented 3 years ago

Example:

cwk_path_set_style(::CWK_STYLE_UNIX);

char buffer[FILENAME_MAX];

cwk_path_get_relative(
    "/dir/dir/",
    "/dir/dir3/file",
    buffer,
    sizeof(buffer));

printf("The relative path is: %s\n", buffer);

Will return The relative path is: file

This is wrong. Expected results should be ../dir3/file

If i change base dir to something else for example from "/dir/dir/" to "/dir/dir2/"

cwk_path_set_style(::CWK_STYLE_UNIX);

char buffer[FILENAME_MAX];

cwk_path_get_relative(
    "/dir/dir2/",
    "/dir/dir3/file",
    buffer,
    sizeof(buffer));

printf("The relative path is: %s\n", buffer);

it will return correct results. The relative path is: ../dir3/file

likle commented 3 years ago

Hi @aomsin2526 ! Thanks for reporting this. I will have a look at it

likle commented 3 years ago

Hi @aomsin2526 , this should be resolved on the master branch. Could you verify? I will create a release with this soon.

aomsin2526 commented 3 years ago

Yes, working as expected now.

likle commented 3 years ago

@aomsin2526 thank you very much for your help! This fix is now in the newest release v1.2.6.