블로그 (Blog)/개발로그 (Devlogs)
절대 패스 <-> 상대 패스 상호 변환
티클러
2025. 10. 23. 15:16
https://likle.github.io/cwalk/
https://github.com/likle/cwalk

C/C++용으로 아주 괜찮은 절대 패스 <-> 상대 패스 상호 변환 라이브러리.. cwalk..
윈도우즈/리눅스 스타일도 지원..
아래와 같이 간단한 래퍼 함수를 만들어봄..
#include <limits.h> // FILENAME_MAX
#include <cwalk.h>
std::string Rel2AbsPath(const std::string& base, const std::string& relative, bool unix_style)
{
if(unix_style)
cwk_path_set_style(CWK_STYLE_UNIX);
else
cwk_path_set_style(CWK_STYLE_WINDOWS);
char buffer[FILENAME_MAX];
cwk_path_get_absolute(base.c_str(), relative.c_str(), buffer, sizeof(buffer));
return std::string(buffer);
}
std::string Abs2RelPath(const std::string& base, const std::string& absolute, bool unix_style)
{
if(unix_style)
cwk_path_set_style(CWK_STYLE_UNIX);
else
cwk_path_set_style(CWK_STYLE_WINDOWS);
char buffer[FILENAME_MAX];
cwk_path_get_relative(base.c_str(), absolute.c_str(), buffer, sizeof(buffer));
return std::string(buffer);
}