@@ -32,80 +32,21 @@ _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
3232
3333namespace detail {
3434
35- #if defined(_LIBCPP_WIN32API)
36-
37- inline errc __win_err_to_errc (int err) {
38- constexpr struct {
39- DWORD win;
40- errc errc;
41- } win_error_mapping[] = {
42- {ERROR_ACCESS_DENIED, errc::permission_denied},
43- {ERROR_ALREADY_EXISTS, errc::file_exists},
44- {ERROR_BAD_NETPATH, errc::no_such_file_or_directory},
45- {ERROR_BAD_PATHNAME, errc::no_such_file_or_directory},
46- {ERROR_BAD_UNIT, errc::no_such_device},
47- {ERROR_BROKEN_PIPE, errc::broken_pipe},
48- {ERROR_BUFFER_OVERFLOW, errc::filename_too_long},
49- {ERROR_BUSY, errc::device_or_resource_busy},
50- {ERROR_BUSY_DRIVE, errc::device_or_resource_busy},
51- {ERROR_CANNOT_MAKE, errc::permission_denied},
52- {ERROR_CANTOPEN, errc::io_error},
53- {ERROR_CANTREAD, errc::io_error},
54- {ERROR_CANTWRITE, errc::io_error},
55- {ERROR_CURRENT_DIRECTORY, errc::permission_denied},
56- {ERROR_DEV_NOT_EXIST, errc::no_such_device},
57- {ERROR_DEVICE_IN_USE, errc::device_or_resource_busy},
58- {ERROR_DIR_NOT_EMPTY, errc::directory_not_empty},
59- {ERROR_DIRECTORY, errc::invalid_argument},
60- {ERROR_DISK_FULL, errc::no_space_on_device},
61- {ERROR_FILE_EXISTS, errc::file_exists},
62- {ERROR_FILE_NOT_FOUND, errc::no_such_file_or_directory},
63- {ERROR_HANDLE_DISK_FULL, errc::no_space_on_device},
64- {ERROR_INVALID_ACCESS, errc::permission_denied},
65- {ERROR_INVALID_DRIVE, errc::no_such_device},
66- {ERROR_INVALID_FUNCTION, errc::function_not_supported},
67- {ERROR_INVALID_HANDLE, errc::invalid_argument},
68- {ERROR_INVALID_NAME, errc::no_such_file_or_directory},
69- {ERROR_INVALID_PARAMETER, errc::invalid_argument},
70- {ERROR_LOCK_VIOLATION, errc::no_lock_available},
71- {ERROR_LOCKED, errc::no_lock_available},
72- {ERROR_NEGATIVE_SEEK, errc::invalid_argument},
73- {ERROR_NOACCESS, errc::permission_denied},
74- {ERROR_NOT_ENOUGH_MEMORY, errc::not_enough_memory},
75- {ERROR_NOT_READY, errc::resource_unavailable_try_again},
76- {ERROR_NOT_SAME_DEVICE, errc::cross_device_link},
77- {ERROR_NOT_SUPPORTED, errc::not_supported},
78- {ERROR_OPEN_FAILED, errc::io_error},
79- {ERROR_OPEN_FILES, errc::device_or_resource_busy},
80- {ERROR_OPERATION_ABORTED, errc::operation_canceled},
81- {ERROR_OUTOFMEMORY, errc::not_enough_memory},
82- {ERROR_PATH_NOT_FOUND, errc::no_such_file_or_directory},
83- {ERROR_READ_FAULT, errc::io_error},
84- {ERROR_REPARSE_TAG_INVALID, errc::invalid_argument},
85- {ERROR_RETRY, errc::resource_unavailable_try_again},
86- {ERROR_SEEK, errc::io_error},
87- {ERROR_SHARING_VIOLATION, errc::permission_denied},
88- {ERROR_TOO_MANY_OPEN_FILES, errc::too_many_files_open},
89- {ERROR_WRITE_FAULT, errc::io_error},
90- {ERROR_WRITE_PROTECT, errc::permission_denied},
91- };
92-
93- for (const auto & pair : win_error_mapping)
94- if (pair.win == static_cast <DWORD>(err))
95- return pair.errc ;
96- return errc::invalid_argument;
97- }
98-
99- #endif // _LIBCPP_WIN32API
35+ // On windows, libc functions use errno, but system functions use GetLastError.
36+ // So, callers need to be careful which of these next functions they call!
10037
10138inline error_code capture_errno () {
10239 _LIBCPP_ASSERT_INTERNAL (errno != 0 , " Expected errno to be non-zero" );
10340 return error_code (errno, generic_category ());
10441}
10542
43+ inline error_code get_last_error () {
10644#if defined(_LIBCPP_WIN32API)
107- inline error_code make_windows_error (int err) { return make_error_code (__win_err_to_errc (err)); }
45+ return std::error_code (GetLastError (), std::system_category ());
46+ #else
47+ return capture_errno ();
10848#endif
49+ }
10950
11051template <class T >
11152T error_value ();
0 commit comments