Skip to content

Commit e9fe2d7

Browse files
committed
hrmmm
1 parent 8e7ad94 commit e9fe2d7

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/basicio.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,28 @@ int FileIo::open(const std::string& mode) {
489489
close();
490490
p_->openMode_ = mode;
491491
p_->opMode_ = Impl::opSeek;
492+
#ifdef _WIN32
493+
auto wMode = [&] {
494+
if (mode == "ab")
495+
return L"ab";
496+
if (mode == "rb")
497+
return L"rb";
498+
if (mode == "wb")
499+
return L"wb";
500+
if (mode == "a+b")
501+
return L"a+b";
502+
if (mode == "r+b")
503+
return L"r+b";
504+
if (mode == "w+b")
505+
return L"w+b";
506+
return L"";
507+
}();
508+
509+
if (_wfopen_s(&p_->fp_, p_->path_.c_str(), wMode))
510+
#else
492511
p_->fp_ = ::fopen(path().c_str(), mode.c_str());
493512
if (!p_->fp_)
513+
#endif
494514
return 1;
495515
return 0;
496516
}
@@ -1641,6 +1661,20 @@ size_t writeFile(const DataBuf& buf, const std::string& path) {
16411661
}
16421662
return file.write(buf.c_data(), buf.size());
16431663
}
1664+
1665+
#ifdef _WIN32
1666+
DataBuf readFile(const std::wstring& path) {
1667+
FileIo file(path);
1668+
if (file.open("rb") != 0) {
1669+
throw Error(ErrorCode::kerFileOpenFailed, "rb", strError());
1670+
}
1671+
DataBuf buf(static_cast<size_t>(fs::file_size(path)));
1672+
if (file.read(buf.data(), buf.size()) != buf.size()) {
1673+
throw Error(ErrorCode::kerCallFailed, strError(), "FileIo::read");
1674+
}
1675+
return buf;
1676+
}
1677+
#endif
16441678
#endif
16451679

16461680
#ifdef EXV_USE_CURL

src/image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ Image::UniquePtr ImageFactory::create(ImageType type, const std::string& path) {
903903
Image::UniquePtr ImageFactory::create(ImageType type, const std::wstring& path) {
904904
auto fileIo = std::make_unique<FileIo>(path);
905905
// Create or overwrite the file, then close it
906-
if (fileIo->open(L"w+b") != 0)
906+
if (fileIo->open("w+b") != 0)
907907
throw Error(ErrorCode::kerFileOpenFailed, "w+b", strError());
908908
fileIo->close();
909909

0 commit comments

Comments
 (0)