Skip to content

Commit

Permalink
Support win32 chinese model path
Browse files Browse the repository at this point in the history
  • Loading branch information
weiliangyuansuq committed Oct 17, 2024
1 parent 60c89b7 commit 39c2871
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion chatglm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ std::string PerfStreamer::to_string() const {
return oss.str();
}

#ifdef _WIN32
static std::wstring convert_to_wstring(const std::string &str) {
int count = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
std::wstring wstr(count, 0);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &wstr[0], count);
return wstr;
}
#endif

#ifdef _POSIX_MAPPED_FILES
MappedFile::MappedFile(const std::string &path) {
int fd = open(path.c_str(), O_RDONLY);
Expand All @@ -318,7 +327,8 @@ MappedFile::~MappedFile() { CHATGLM_CHECK(munmap(data, size) == 0) << strerror(e
#elif defined(_WIN32)
MappedFile::MappedFile(const std::string &path) {

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

struct _stat64 sb;
Expand Down

0 comments on commit 39c2871

Please sign in to comment.