From c841928969dea9e561290d4da991e73d8e4f78ee Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Wed, 12 Jul 2023 23:36:07 +0800 Subject: [PATCH 1/2] merge `_Current_path(path&)noexcept` into `path current_path(error_code&)` --- stl/inc/filesystem | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 30a92a9a82e..cfa1b87c85d 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -619,7 +619,7 @@ namespace filesystem { friend inline __std_win_error _Absolute(path& _Result, const wstring& _Text); friend inline __std_win_error _Canonical(path& _Result, const wstring& _Text); friend inline path temp_directory_path(error_code& _Ec); - friend inline __std_win_error _Current_path(path& _Result) noexcept; + friend inline path current_path(error_code& _Ec); friend inline void current_path(const path& _To); friend inline void current_path(const path& _To, error_code& _Ec) noexcept; friend inline __std_win_error _Read_symlink(const path& _Symlink_path, path& _Result) noexcept; @@ -1818,6 +1818,10 @@ namespace filesystem { _THROW(filesystem_error(_Op, _Path1, _Path2, _Make_ec(_Error))); } + [[noreturn]] inline void _Throw_fs_error(const char* _Op, const error_code& _Error) { + _THROW(filesystem_error(_Op, _Error)); + } + [[noreturn]] inline void _Throw_fs_error(const char* _Op, const error_code& _Error, const path& _Path1) { _THROW(filesystem_error(_Op, _Path1, _Error)); } @@ -4042,30 +4046,28 @@ namespace filesystem { return _Result; } - _NODISCARD inline __std_win_error _Current_path(path& _Result) noexcept { + _EXPORT_STD _NODISCARD inline path current_path(error_code& _Ec) { + _Ec.clear(); + path _Result; _Result._Text.resize(__std_fs_max_path); for (;;) { const auto _Requested_size = static_cast(_Result._Text.size()); const auto _Temp_result = __std_fs_get_current_path(_Requested_size, _Result._Text.data()); _Result._Text.resize(_Temp_result._Size); if (_Temp_result._Size < _Requested_size) { - return _Temp_result._Error; + _Ec = _Make_ec(_Temp_result._Error); + break; } } - } - _EXPORT_STD _NODISCARD inline path current_path(error_code& _Ec) { - _Ec.clear(); - path _Result; - _Ec = _Make_ec(_Current_path(_Result)); return _Result; } _EXPORT_STD _NODISCARD inline path current_path() { - path _Result; - const auto _Err = _Current_path(_Result); - if (_Err != __std_win_error::_Success) { - _Throw_fs_error("current_path()", _Err); + error_code _Ec; + path _Result(_STD filesystem::current_path(_Ec)); + if (_Ec) { + _Throw_fs_error("current_path()", _Ec); } return _Result; } From d1d7f14127e89e99661b9de051e1a30eefa97a35 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 12 Jul 2023 18:01:58 -0700 Subject: [PATCH 2/2] Code review feedback. --- stl/inc/filesystem | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index cfa1b87c85d..9765fd62bca 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -4056,11 +4056,9 @@ namespace filesystem { _Result._Text.resize(_Temp_result._Size); if (_Temp_result._Size < _Requested_size) { _Ec = _Make_ec(_Temp_result._Error); - break; + return _Result; } } - - return _Result; } _EXPORT_STD _NODISCARD inline path current_path() {