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

void cwk_realpath_from_relative(const char *relativepath, char *realpath, size_t *length); #4

Closed wrenashe closed 4 years ago

wrenashe commented 5 years ago

Could you please also add one more API, getting realpath of file from its relative file path, like void cwk_realpath_from_relative(const char relativepath, char realpath, size_t *length);

cwk_realpath_from_relative("my/mine.txt", realpath, length), once it is returned, *realpath = "/work/path/my/mine.txt"....

likle commented 5 years ago

Hi @wrenashe

If I understand you correctly, you would like to generate an absolute path, using a base path and a relative path. If that's the case, cwk_path_get_absolute may be helpful:

  char buffer[FILENAME_MAX];
  cwk_path_get_absolute("/hello/there", "./world", buffer, sizeof(buffer));
  printf("The absolute path is: %s", buffer);
  // Output: The absolute path is: /hello/there/world

If you'd like to get the realpath using the current working directory, you can just pass the current working directory to the first parameter. Are you actually looking for a function which automatically applies the current working directory?

wrenashe commented 4 years ago

Thanks.