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
253 stars 40 forks source link

get_absolute creates only UNIX paths if base is not absolute #14

Closed bgrieco closed 4 years ago

bgrieco commented 4 years ago

on line 651

  // The basename should be an absolute path if the caller is using the API
  // correctly. However, he might not and in that case we will append a fake
  // root at the beginning.
  if (cwk_path_is_absolute(base)) {
    i = 0;
  } else {
    paths[0] = "/";
    i = 1;
  }

The function produces a weird Unix path if the base is not absolute in windows. There could be some thought about trying to see if the appended path has a root in those cases since assuming c:\ as a root is not the best option.

BTW, I stumbled on this because I tried path_join and could not produce absolute paths with it.

likle commented 4 years ago

Hi @bgrieco !

This is indeed imperfect. I am going to change cwk_path_get_absolute to use a backslash instead, since a backslash without drive letter will reference to the current drive. Please don't call cwk_path_get_absolute with a relative base. The base should be absolute.

I would really be interested in what didn't work with path_join and appreciate further information there!

likle commented 4 years ago

I pushed those changes in https://github.com/likle/cwalk/commit/1dac5f18c12c89933d6ea8264a10a2ef02304e74, they are available on the master branch.

likle commented 4 years ago

Please let me know if you still encounter issues with this after the previous commit.