Index: operations.cpp =================================================================== --- operations.cpp (revision 78142) +++ operations.cpp (working copy) @@ -596,9 +596,12 @@ ::GetFullPathNameW(src.c_str(), static_cast(len), buf, p)); } - fs::file_status process_status_failure(const path& p, error_code* ec) + fs::file_status process_status_failure(const path& p, int errval, error_code* ec) { - int errval(::GetLastError()); + // Some compilers can call ::SetLastError(0) just before process_status_failure + // is called. It is much safer to call ::GetLastError() in a function, + // that triggered a failure. + //int errval(::GetLastError()); if (ec != 0) // always report errval, even though some ec->assign(errval, system_category()); // errval values are not status_errors @@ -623,7 +626,7 @@ DWORD attr(::GetFileAttributesW(p.c_str())); if (attr == 0xFFFFFFFF) { - return process_status_failure(p, ec).type(); + return process_status_failure(p, ::GetLastError(), ec).type(); } if (ec != 0) ec->clear(); @@ -1616,7 +1619,7 @@ DWORD attr(::GetFileAttributesW(p.c_str())); if (attr == 0xFFFFFFFF) { - return process_status_failure(p, ec); + return process_status_failure(p, ::GetLastError(), ec); } // reparse point handling; @@ -1635,7 +1638,7 @@ 0)); // hTemplateFile if (h.handle == INVALID_HANDLE_VALUE) { - return process_status_failure(p, ec); + return process_status_failure(p, ::GetLastError(), ec); } if (!is_reparse_point_a_symlink(p)) @@ -1699,7 +1702,7 @@ DWORD attr(::GetFileAttributesW(p.c_str())); if (attr == 0xFFFFFFFF) { - return process_status_failure(p, ec); + return process_status_failure(p, ::GetLastError(), ec); } if (ec != 0) ec->clear();