From e2d56c09497de082083721af765f979b22ebae21 Mon Sep 17 00:00:00 2001 From: Fros1er <34234343+Fros1er@users.noreply.github.com> Date: Wed, 15 Feb 2023 21:32:37 +0800 Subject: [PATCH] reuse open_windows_file on ctor --- src/os.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/os.cc b/src/os.cc index e49a8186..d4961c9b 100644 --- a/src/os.cc +++ b/src/os.cc @@ -223,15 +223,13 @@ file::file(cstring_view path, int oflag) { # if defined(_WIN32) && !defined(__MINGW32__) fd_ = -1; auto converted = detail::utf8_to_utf16(string_view(path.c_str())); - auto err = - _wsopen_s(&fd_, converted.c_str(), oflag, _SH_DENYNO, default_open_mode); + *this = file::open_windows_file(converted.c_str(), oflag); # else FMT_RETRY(fd_, FMT_POSIX_CALL(open(path.c_str(), oflag, default_open_mode))); - auto err = errno; -# endif if (fd_ == -1) FMT_THROW( - system_error(err, FMT_STRING("cannot open file {}"), path.c_str())); + system_error(errno, FMT_STRING("cannot open file {}"), path.c_str())); +# endif } file::~file() noexcept {