Skip to content

Commit d8c1500

Browse files
committed
Fix StandardPaths::openPath on certain platform
Certain platform there might be overload function to ::open(), use a template function to wrap it instead of using function pointer. Otherwise we would need to write the full signature of open, which is undesirable since certain platform may have non-standard signature.
1 parent aa682fd commit d8c1500

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/lib/fcitx-utils/standardpaths.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,15 @@ UnixFD StandardPaths::openPath(const std::filesystem::path &path,
252252
std::optional<int> flags,
253253
std::optional<mode_t> mode) {
254254
int f = flags.value_or(O_RDONLY);
255+
256+
auto openFunc = [](auto path, int flag, auto... extra) {
255257
#ifdef _WIN32
256-
f |= _O_BINARY;
257-
auto openFunc = ::_wopen;
258+
flag |= _O_BINARY;
259+
return ::_wopen(path, flag, extra...);
258260
#else
259-
auto openFunc = ::open;
261+
return ::open(path, flag, extra...);
260262
#endif
263+
};
261264
if (mode.has_value()) {
262265
return UnixFD::own(openFunc(path.c_str(), f, mode.value()));
263266
}

0 commit comments

Comments
 (0)