Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert utf8 paths to utf16 on windows when UNICODE is enabled #672

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/easylogging++.cc
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,15 @@ namespace utils {
// File

base::type::fstream_t* File::newFileStream(const std::string& filename) {
base::type::fstream_t *fs = new base::type::fstream_t(filename.c_str(),
// assume utf-8 encoded std::string
#if ELPP_OS_WINDOWS
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> utf16conv;
std::wstring wfilename = utf16conv.from_bytes(filename);
base::type::fstream_t *fs = new base::type::fstream_t( wfilename,
#else
base::type::fstream_t *fs = new base::type::fstream_t( filename.c_str(),
#endif // defined(ELPP_UNICODE)

base::type::fstream_t::out
#if !defined(ELPP_FRESH_LOG_FILE)
| base::type::fstream_t::app
Expand Down Expand Up @@ -772,7 +780,12 @@ bool File::pathExists(const char* path, bool considerFile) {
struct stat st;
return (stat(path, &st) == 0);
#elif ELPP_OS_WINDOWS
# if defined(ELPP_UNICODE)
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> utf16conv;
DWORD fileType = GetFileAttributesW(utf16conv.from_bytes(path).c_str());
# else
DWORD fileType = GetFileAttributesA(path);
# endif // defined(ELPP_UNICODE)
if (fileType == INVALID_FILE_ATTRIBUTES) {
return false;
}
Expand Down Expand Up @@ -809,7 +822,12 @@ bool File::createPath(const std::string& path) {
status = mkdir(builtPath.c_str(), ELPP_LOG_PERMS);
currPath = STRTOK(nullptr, base::consts::kFilePathSeperator, 0);
#elif ELPP_OS_WINDOWS
# if defined(ELPP_UNICODE)
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> utf16conv;
status = _wmkdir(utf16conv.from_bytes(builtPath).c_str());
# else
status = _mkdir(builtPath.c_str());
# endif // defined(ELPP_UNICODE)
currPath = STRTOK(nullptr, base::consts::kFilePathSeperator, &nextTok_);
#endif // ELPP_OS_UNIX
}
Expand Down