Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 39c2871

Browse files
committedOct 17, 2024
Support win32 chinese model path
1 parent 60c89b7 commit 39c2871

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed
 

‎chatglm.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ std::string PerfStreamer::to_string() const {
299299
return oss.str();
300300
}
301301

302+
#ifdef _WIN32
303+
static std::wstring convert_to_wstring(const std::string &str) {
304+
int count = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
305+
std::wstring wstr(count, 0);
306+
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &wstr[0], count);
307+
return wstr;
308+
}
309+
#endif
310+
302311
#ifdef _POSIX_MAPPED_FILES
303312
MappedFile::MappedFile(const std::string &path) {
304313
int fd = open(path.c_str(), O_RDONLY);
@@ -318,7 +327,8 @@ MappedFile::~MappedFile() { CHATGLM_CHECK(munmap(data, size) == 0) << strerror(e
318327
#elif defined(_WIN32)
319328
MappedFile::MappedFile(const std::string &path) {
320329

321-
int fd = open(path.c_str(), O_RDONLY);
330+
const std::wstring wpath = convert_to_wstring(path);
331+
int fd = _wopen(wpath.c_str(), O_RDONLY);
322332
CHATGLM_CHECK(fd > 0) << "cannot open file " << path << ": " << strerror(errno);
323333

324334
struct _stat64 sb;

0 commit comments

Comments
 (0)
Please sign in to comment.