diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 000b677..7af17ab 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -1069,6 +1069,11 @@ enum class portable_error { is_a_directory, }; GHC_FS_API std::error_code make_error_code(portable_error err); +#ifdef GHC_OS_WINDOWS +GHC_FS_API std::error_code make_system_error(DWORD err = 0); +#else +GHC_FS_API std::error_code make_system_error(int err = 0); +#endif } // namespace detail namespace detail { @@ -1119,6 +1124,18 @@ GHC_INLINE std::error_code make_error_code(portable_error err) return std::error_code(); } +#ifdef GHC_OS_WINDOWS +GHC_INLINE std::error_code make_system_error(DWORD err) +{ + return std::error_code(err ? static_cast(err) : static_cast(::GetLastError()), std::system_category()); +} +#else +GHC_INLINE std::error_code make_system_error(int err) +{ + return std::error_code(err ? err : errno, std::system_category()); +} +#endif + #endif // GHC_EXPAND_IMPL template @@ -1546,7 +1563,7 @@ GHC_INLINE std::string systemErrorText(ErrorNumber code = 0) { #if defined(GHC_OS_WINDOWS) LPVOID msgBuf; - DWORD dw = code ? code : ::GetLastError(); + DWORD dw = code ? static_cast(code) : ::GetLastError(); FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&msgBuf, 0, NULL); std::string msg = toUtf8(std::wstring((LPWSTR)msgBuf)); LocalFree(msgBuf); @@ -1576,11 +1593,11 @@ GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, if (result == ERROR_PRIVILEGE_NOT_HELD && api_call(detail::fromUtf8(new_symlink.u8string()).c_str(), detail::fromUtf8(target_name.u8string()).c_str(), to_directory ? 3 : 2) != 0) { return; } - ec = std::error_code(result, std::system_category()); + ec = detail::make_system_error(result); } } else { - ec = std::error_code(ERROR_NOT_SUPPORTED, std::system_category()); + ec = detail::make_system_error(ERROR_NOT_SUPPORTED); } } @@ -1589,25 +1606,25 @@ GHC_INLINE void create_hardlink(const path& target_name, const path& new_hardlin static CreateHardLinkW_fp api_call = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "CreateHardLinkW")); if (api_call) { if (api_call(detail::fromUtf8(new_hardlink.u8string()).c_str(), detail::fromUtf8(target_name.u8string()).c_str(), NULL) == 0) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } } else { - ec = std::error_code(ERROR_NOT_SUPPORTED, std::system_category()); + ec = detail::make_system_error(ERROR_NOT_SUPPORTED); } } #else GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, bool, std::error_code& ec) { if (::symlink(target_name.c_str(), new_symlink.c_str()) != 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); } } GHC_INLINE void create_hardlink(const path& target_name, const path& new_hardlink, std::error_code& ec) { if (::link(target_name.c_str(), new_hardlink.c_str()) != 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); } } #endif @@ -1697,7 +1714,7 @@ GHC_INLINE path resolveSymlink(const path& p, std::error_code& ec) std::shared_ptr file(CreateFileW(p.wstring().c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0), CloseHandle); if (file.get() == INVALID_HANDLE_VALUE) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); return path(); } @@ -1719,7 +1736,7 @@ GHC_INLINE path resolveSymlink(const path& p, std::error_code& ec) } } else { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } return result; #else @@ -1728,7 +1745,7 @@ GHC_INLINE path resolveSymlink(const path& p, std::error_code& ec) std::vector buffer(bufferSize, (char)0); auto rc = ::readlink(p.c_str(), buffer.data(), buffer.size()); if (rc < 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return path(); } else if (rc < static_cast(bufferSize)) { @@ -1746,15 +1763,15 @@ GHC_INLINE time_t timeFromFILETIME(const FILETIME& ft) ULARGE_INTEGER ull; ull.LowPart = ft.dwLowDateTime; ull.HighPart = ft.dwHighDateTime; - return ull.QuadPart / 10000000ULL - 11644473600ULL; + return static_cast(ull.QuadPart / 10000000ULL - 11644473600ULL); } GHC_INLINE void timeToFILETIME(time_t t, FILETIME& ft) { LONGLONG ll; ll = Int32x32To64(t, 10000000) + 116444736000000000; - ft.dwLowDateTime = (DWORD)ll; - ft.dwHighDateTime = ll >> 32; + ft.dwLowDateTime = static_cast(ll); + ft.dwHighDateTime = static_cast(ll >> 32); } template @@ -1818,7 +1835,7 @@ GHC_INLINE file_status symlink_status_ex(const path& p, std::error_code& ec, uin file_status fs; WIN32_FILE_ATTRIBUTE_DATA attr; if (!GetFileAttributesExW(detail::fromUtf8(p.u8string()).c_str(), GetFileExInfoStandard, &attr)) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } else { ec.clear(); @@ -1845,7 +1862,7 @@ GHC_INLINE file_status symlink_status_ex(const path& p, std::error_code& ec, uin file_status f_s = detail::file_status_from_st_mode(fs.st_mode); return f_s; } - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); if (detail::is_not_found_error(ec)) { return file_status(file_type::not_found, perms::unknown); } @@ -1858,12 +1875,12 @@ GHC_INLINE file_status status_ex(const path& p, std::error_code& ec, file_status ec.clear(); #ifdef GHC_OS_WINDOWS if (recurse_count > 16) { - ec = std::error_code(0x2A9 /*ERROR_STOPPED_ON_SYMLINK*/, std::system_category()); + ec = detail::make_system_error(0x2A9 /*ERROR_STOPPED_ON_SYMLINK*/); return file_status(file_type::unknown); } WIN32_FILE_ATTRIBUTE_DATA attr; if (!::GetFileAttributesExW(p.wstring().c_str(), GetFileExInfoStandard, &attr)) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } else if (attr.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { path target = resolveSymlink(p, ec); @@ -1914,7 +1931,7 @@ GHC_INLINE file_status status_ex(const path& p, std::error_code& ec, file_status return fs; } else { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); if (detail::is_not_found_error(ec)) { return file_status(file_type::not_found, perms::unknown); } @@ -1935,8 +1952,8 @@ GHC_INLINE u8arguments::u8arguments(int& argc, char**& argv) #ifdef GHC_OS_WINDOWS LPWSTR* p; p = ::CommandLineToArgvW(::GetCommandLineW(), &argc); - _args.reserve(argc); - _argp.reserve(argc); + _args.reserve(static_cast(argc)); + _argp.reserve(static_cast(argc)); for (size_t i = 0; i < static_cast(argc); ++i) { _args.push_back(detail::toUtf8(std::wstring(p[i]))); _argp.push_back((char*)_args[i].data()); @@ -3013,7 +3030,7 @@ GHC_INLINE path absolute(const path& p, std::error_code& ec) return result; } } - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); return path(); #else path base = current_path(ec); @@ -3038,7 +3055,7 @@ GHC_INLINE path absolute(const path& p, std::error_code& ec) } } } - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return path(); #endif } @@ -3250,12 +3267,12 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options if ((options & copy_options::update_existing) == copy_options::update_existing) { auto from_time = last_write_time(from, ec); if (ec) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return false; } auto to_time = last_write_time(to, ec); if (ec) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return false; } if (from_time <= to_time) { @@ -3266,7 +3283,7 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options } #ifdef GHC_OS_WINDOWS if (!::CopyFileW(detail::fromUtf8(from.u8string()).c_str(), detail::fromUtf8(to.u8string()).c_str(), !overwrite)) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); return false; } return true; @@ -3274,7 +3291,7 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options std::vector buffer(16384, '\0'); int in = -1, out = -1; if ((in = ::open(from.c_str(), O_RDONLY)) < 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return false; } std::shared_ptr guard_in(nullptr, [in](void*) { ::close(in); }); @@ -3283,7 +3300,7 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options mode |= O_EXCL; } if ((out = ::open(to.c_str(), mode, static_cast(sf.permissions() & perms::all))) < 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return false; } std::shared_ptr guard_out(nullptr, [out](void*) { ::close(out); }); @@ -3296,7 +3313,7 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options offset += bw; } else if (bw < 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return false; } } while (br); @@ -3410,12 +3427,12 @@ GHC_INLINE bool create_directory(const path& p, const path& attributes, std::err #ifdef GHC_OS_WINDOWS if (!attributes.empty()) { if (!::CreateDirectoryExW(detail::fromUtf8(attributes.u8string()).c_str(), detail::fromUtf8(p.u8string()).c_str(), NULL)) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); return false; } } else if (!::CreateDirectoryW(detail::fromUtf8(p.u8string()).c_str(), NULL)) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); return false; } #else @@ -3423,13 +3440,13 @@ GHC_INLINE bool create_directory(const path& p, const path& attributes, std::err if (!attributes.empty()) { struct ::stat fileStat; if (::stat(attributes.c_str(), &fileStat) != 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return false; } attribs = fileStat.st_mode; } if (::mkdir(p.c_str(), attribs) != 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return false; } #endif @@ -3495,7 +3512,7 @@ GHC_INLINE path current_path(std::error_code& ec) DWORD pathlen = ::GetCurrentDirectoryW(0, 0); std::unique_ptr buffer(new wchar_t[size_t(pathlen) + 1]); if (::GetCurrentDirectoryW(pathlen, buffer.get()) == 0) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); return path(); } return path(std::wstring(buffer.get()), path::native_format); @@ -3503,7 +3520,7 @@ GHC_INLINE path current_path(std::error_code& ec) size_t pathlen = static_cast(std::max(int(::pathconf(".", _PC_PATH_MAX)), int(PATH_MAX))); std::unique_ptr buffer(new char[pathlen + 1]); if (::getcwd(buffer.get(), pathlen) == NULL) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return path(); } return path(buffer.get()); @@ -3524,11 +3541,11 @@ GHC_INLINE void current_path(const path& p, std::error_code& ec) noexcept ec.clear(); #ifdef GHC_OS_WINDOWS if (!::SetCurrentDirectoryW(detail::fromUtf8(p.u8string()).c_str())) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } #else if (::chdir(p.string().c_str()) == -1) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); } #endif } @@ -3571,21 +3588,21 @@ GHC_INLINE bool equivalent(const path& p1, const path& p2, std::error_code& ec) std::shared_ptr file2(::CreateFileW(p2.wstring().c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0), CloseHandle); if (file1.get() == INVALID_HANDLE_VALUE || file2.get() == INVALID_HANDLE_VALUE) { #ifdef LWG_2937_BEHAVIOUR - ec = std::error_code(e1 ? e1 : ::GetLastError(), std::system_category()); + ec = detail::make_system_error(e1 ? e1 : ::GetLastError()); #else if (file1 == file2) { - ec = std::error_code(e1 ? e1 : ::GetLastError(), std::system_category()); + ec = detail::make_system_error(e1 ? e1 : ::GetLastError()); } #endif return false; } BY_HANDLE_FILE_INFORMATION inf1, inf2; if (!::GetFileInformationByHandle(file1.get(), &inf1)) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); return false; } if (!::GetFileInformationByHandle(file2.get(), &inf2)) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); return false; } return inf1.ftLastWriteTime.dwLowDateTime == inf2.ftLastWriteTime.dwLowDateTime && inf1.ftLastWriteTime.dwHighDateTime == inf2.ftLastWriteTime.dwHighDateTime && inf1.nFileIndexHigh == inf2.nFileIndexHigh && inf1.nFileIndexLow == inf2.nFileIndexLow && @@ -3597,10 +3614,10 @@ GHC_INLINE bool equivalent(const path& p1, const path& p2, std::error_code& ec) auto rc2 = ::stat(p2.c_str(), &s2); if (rc1 || rc2) { #ifdef LWG_2937_BEHAVIOUR - ec = std::error_code(e1 ? e1 : errno, std::system_category()); + ec = detail::make_system_error(e1 ? e1 : errno); #else if (rc1 && rc2) { - ec = std::error_code(e1 ? e1 : errno, std::system_category()); + ec = detail::make_system_error(e1 ? e1 : errno); } #endif return false; @@ -3625,14 +3642,14 @@ GHC_INLINE uintmax_t file_size(const path& p, std::error_code& ec) noexcept #ifdef GHC_OS_WINDOWS WIN32_FILE_ATTRIBUTE_DATA attr; if (!GetFileAttributesExW(detail::fromUtf8(p.u8string()).c_str(), GetFileExInfoStandard, &attr)) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); return static_cast(-1); } return static_cast(attr.nFileSizeHigh) << (sizeof(attr.nFileSizeHigh) * 8) | attr.nFileSizeLow; #else struct ::stat fileStat; if (::stat(p.c_str(), &fileStat) == -1) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return static_cast(-1); } return static_cast(fileStat.st_size); @@ -3657,11 +3674,11 @@ GHC_INLINE uintmax_t hard_link_count(const path& p, std::error_code& ec) noexcep std::shared_ptr file(::CreateFileW(p.wstring().c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0), CloseHandle); BY_HANDLE_FILE_INFORMATION inf; if (file.get() == INVALID_HANDLE_VALUE) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } else { if (!::GetFileInformationByHandle(file.get(), &inf)) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } else { result = inf.nNumberOfLinks; @@ -3865,10 +3882,10 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err std::shared_ptr file(::CreateFileW(p.wstring().c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL), ::CloseHandle); FILETIME ft; auto tt = std::chrono::duration_cast(d).count() * 10 + 116444736000000000; - ft.dwLowDateTime = (unsigned long)tt; - ft.dwHighDateTime = tt >> 32; + ft.dwLowDateTime = static_cast(tt); + ft.dwHighDateTime = static_cast(tt >> 32); if (!::SetFileTime(file.get(), 0, 0, &ft)) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } #elif defined(GHC_OS_MACOS) #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED @@ -3884,7 +3901,7 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err return; } } - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return; #else struct ::timespec times[2]; @@ -3893,7 +3910,7 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err times[1].tv_sec = std::chrono::duration_cast(d).count(); times[1].tv_nsec = std::chrono::duration_cast(d).count() % 1000000000; if (::utimensat(AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); } return; #endif @@ -3905,7 +3922,7 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err times[1].tv_sec = std::chrono::duration_cast(d).count(); times[1].tv_nsec = std::chrono::duration_cast(d).count() % 1000000000; if (::utimensat(AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); } return; #endif @@ -3944,12 +3961,12 @@ GHC_INLINE void permissions(const path& p, perms prms, perm_options opts, std::e #ifdef __GNUC__ auto oldAttr = GetFileAttributesW(p.wstring().c_str()); if (oldAttr != INVALID_FILE_ATTRIBUTES) { - DWORD newAttr = ((prms & perms::owner_write) == perms::owner_write) ? oldAttr & ~FILE_ATTRIBUTE_READONLY : oldAttr | FILE_ATTRIBUTE_READONLY; + DWORD newAttr = ((prms & perms::owner_write) == perms::owner_write) ? oldAttr & ~(static_cast(FILE_ATTRIBUTE_READONLY)) : oldAttr | FILE_ATTRIBUTE_READONLY; if (oldAttr == newAttr || SetFileAttributesW(p.wstring().c_str(), newAttr)) { return; } } - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); #else int mode = 0; if ((prms & perms::owner_read) == perms::owner_read) { @@ -3959,13 +3976,13 @@ GHC_INLINE void permissions(const path& p, perms prms, perm_options opts, std::e mode |= _S_IWRITE; } if (::_wchmod(p.wstring().c_str(), mode) != 0) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } #endif #else if ((opts & perm_options::nofollow) != perm_options::nofollow) { if (::chmod(p.c_str(), static_cast(prms)) != 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); } } #endif @@ -4043,17 +4060,17 @@ GHC_INLINE bool remove(const path& p, std::error_code& ec) noexcept if (error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND) { return false; } - ec = std::error_code(error, std::system_category()); + ec = detail::make_system_error(error); } if (!ec) { if (attr & FILE_ATTRIBUTE_DIRECTORY) { if (!RemoveDirectoryW(np.c_str())) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } } else { if (!DeleteFileW(np.c_str())) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } } } @@ -4063,7 +4080,7 @@ GHC_INLINE bool remove(const path& p, std::error_code& ec) noexcept if (error == ENOENT) { return false; } - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); } #endif return ec ? false : true; @@ -4135,13 +4152,13 @@ GHC_INLINE void rename(const path& from, const path& to, std::error_code& ec) no #ifdef GHC_OS_WINDOWS if (from != to) { if (!MoveFileW(detail::fromUtf8(from.u8string()).c_str(), detail::fromUtf8(to.u8string()).c_str())) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } } #else if (from != to) { if (::rename(from.c_str(), to.c_str()) != 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); } } #endif @@ -4161,17 +4178,21 @@ GHC_INLINE void resize_file(const path& p, uintmax_t size, std::error_code& ec) ec.clear(); #ifdef GHC_OS_WINDOWS LARGE_INTEGER lisize; - lisize.QuadPart = size; + lisize.QuadPart = static_cast(size); + if(lisize.QuadPart < 0) { + ec = detail::make_system_error(ERROR_FILE_TOO_LARGE); + return; + } std::shared_ptr file(CreateFileW(detail::fromUtf8(p.u8string()).c_str(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL), CloseHandle); if (file.get() == INVALID_HANDLE_VALUE) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } else if (SetFilePointerEx(file.get(), lisize, NULL, FILE_BEGIN) == 0 || SetEndOfFile(file.get()) == 0) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); } #else if (::truncate(p.c_str(), static_cast(size)) != 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); } #endif } @@ -4194,14 +4215,14 @@ GHC_INLINE space_info space(const path& p, std::error_code& ec) noexcept ULARGE_INTEGER totalNumberOfBytes = {0, 0}; ULARGE_INTEGER totalNumberOfFreeBytes = {0, 0}; if (!GetDiskFreeSpaceExW(detail::fromUtf8(p.u8string()).c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); return {static_cast(-1), static_cast(-1), static_cast(-1)}; } return {static_cast(totalNumberOfBytes.QuadPart), static_cast(totalNumberOfFreeBytes.QuadPart), static_cast(freeBytesAvailableToCaller.QuadPart)}; #elif !defined(__ANDROID__) || __ANDROID_API__ >= 19 struct ::statvfs sfs; if (::statvfs(p.c_str(), &sfs) != 0) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); return {static_cast(-1), static_cast(-1), static_cast(-1)}; } return {static_cast(sfs.f_blocks * sfs.f_frsize), static_cast(sfs.f_bfree * sfs.f_frsize), static_cast(sfs.f_bavail * sfs.f_frsize)}; @@ -4261,9 +4282,9 @@ GHC_INLINE path temp_directory_path(std::error_code& ec) noexcept ec.clear(); #ifdef GHC_OS_WINDOWS wchar_t buffer[512]; - int rc = GetTempPathW(511, buffer); + auto rc = GetTempPathW(511, buffer); if (!rc || rc > 511) { - ec = std::error_code(::GetLastError(), std::system_category()); + ec = detail::make_system_error(); return path(); } return path(std::wstring(buffer)); @@ -4712,7 +4733,7 @@ class directory_iterator::impl auto error = ::GetLastError(); _base = filesystem::path(); if (error != ERROR_ACCESS_DENIED || (options & directory_options::skip_permission_denied) == directory_options::none) { - _ec = std::error_code(::GetLastError(), std::system_category()); + _ec = detail::make_system_error(); } } } @@ -4743,7 +4764,7 @@ class directory_iterator::impl else { auto err = ::GetLastError(); if(err != ERROR_NO_MORE_FILES) { - _ec = ec = std::error_code(err, std::system_category()); + _ec = ec = detail::make_system_error(err); } FindClose(_dirHandle); _dirHandle = INVALID_HANDLE_VALUE; @@ -4803,7 +4824,7 @@ class directory_iterator::impl auto error = errno; _base = filesystem::path(); if (error != EACCES || (options & directory_options::skip_permission_denied) == directory_options::none) { - _ec = std::error_code(errno, std::system_category()); + _ec = detail::make_system_error(); } } else { @@ -4834,7 +4855,7 @@ class directory_iterator::impl _dir = nullptr; _current = path(); if (errno) { - ec = std::error_code(errno, std::system_category()); + ec = detail::make_system_error(); } break; }