From 93e5ec2cba6656417c9502ad80709aeca5eac968 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Mon, 6 Dec 2010 04:28:01 +0000 Subject: KillTheDoctor: Cleanup error_code usage. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120986 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/KillTheDoctor/KillTheDoctor.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'utils/KillTheDoctor') diff --git a/utils/KillTheDoctor/KillTheDoctor.cpp b/utils/KillTheDoctor/KillTheDoctor.cpp index 282cfda8a6..a623d6af8d 100644 --- a/utils/KillTheDoctor/KillTheDoctor.cpp +++ b/utils/KillTheDoctor/KillTheDoctor.cpp @@ -164,10 +164,6 @@ namespace { typedef ScopedHandle ThreadScopedHandle; typedef ScopedHandle TokenScopedHandle; typedef ScopedHandle FileScopedHandle; - - error_code get_windows_last_error() { - return make_error_code(windows_error(::GetLastError())); - } } static error_code GetFileNameFromHandle(HANDLE FileHandle, @@ -181,7 +177,7 @@ static error_code GetFileNameFromHandle(HANDLE FileHandle, Sucess = ::GetFileSizeEx(FileHandle, &FileSize); if (!Sucess) - return get_windows_last_error(); + return windows_error(::GetLastError()); // Create a file mapping object. FileMappingScopedHandle FileMapping( @@ -193,14 +189,14 @@ static error_code GetFileNameFromHandle(HANDLE FileHandle, NULL)); if (!FileMapping) - return get_windows_last_error(); + return windows_error(::GetLastError()); // Create a file mapping to get the file name. MappedViewOfFileScopedHandle MappedFile( ::MapViewOfFile(FileMapping, FILE_MAP_READ, 0, 0, 1)); if (!MappedFile) - return get_windows_last_error(); + return windows_error(::GetLastError()); Sucess = ::GetMappedFileNameA(::GetCurrentProcess(), MappedFile, @@ -208,7 +204,7 @@ static error_code GetFileNameFromHandle(HANDLE FileHandle, array_lengthof(Filename) - 1); if (!Sucess) - return get_windows_last_error(); + return windows_error(::GetLastError()); else { Name = Filename; return windows_error::success; @@ -256,10 +252,10 @@ static std::string FindProgram(const std::string &Program, error_code &ec) { PathName, NULL); if (length == 0) - ec = get_windows_last_error(); + ec = windows_error(::GetLastError()); else if (length > array_lengthof(PathName)) { // This may have been the file, return with error. - ec = error_code(windows_error::buffer_overflow); + ec = windows_error::buffer_overflow; break; } else { // We found the path! Return it. @@ -279,7 +275,7 @@ static error_code EnableDebugPrivileges() { TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &TokenHandle); if (!success) - return error_code(::GetLastError(), system_category()); + return windows_error(::GetLastError()); TokenScopedHandle Token(TokenHandle); TOKEN_PRIVILEGES TokenPrivileges; @@ -289,7 +285,7 @@ static error_code EnableDebugPrivileges() { SE_DEBUG_NAME, &LocallyUniqueID); if (!success) - return error_code(::GetLastError(), system_category()); + return windows_error(::GetLastError()); TokenPrivileges.PrivilegeCount = 1; TokenPrivileges.Privileges[0].Luid = LocallyUniqueID; @@ -303,7 +299,7 @@ static error_code EnableDebugPrivileges() { NULL); // The value of success is basically useless. Either way we are just returning // the value of ::GetLastError(). - return error_code(::GetLastError(), system_category()); + return windows_error(::GetLastError()); } static StringRef ExceptionCodeToString(DWORD ExceptionCode) { @@ -404,7 +400,7 @@ int main(int argc, char **argv) { &ProcessInfo); if (!success) { errs() << ToolName << ": Failed to run program: '" << ProgramToRun - << "': " << error_code(::GetLastError(), system_category()).message() + << "': " << error_code(windows_error(::GetLastError())).message() << '\n'; return -1; } @@ -432,7 +428,7 @@ int main(int argc, char **argv) { &KernelTime, &UserTime); if (!success) { - ec = error_code(::GetLastError(), system_category()); + ec = windows_error(::GetLastError()); errs() << ToolName << ": Failed to get process times: " << ec.message() << '\n'; @@ -467,9 +463,9 @@ int main(int argc, char **argv) { success = WaitForDebugEvent(&DebugEvent, TimeLeft); if (!success) { - ec = error_code(::GetLastError(), system_category()); + ec = windows_error(::GetLastError()); - if (ec == error_condition(errc::timed_out)) { + if (ec == errc::timed_out) { errs() << ToolName << ": Process timed out.\n"; ::TerminateProcess(ProcessInfo.hProcess, -1); // Otherwise other stuff starts failing... @@ -586,7 +582,7 @@ int main(int argc, char **argv) { DebugEvent.dwThreadId, dwContinueStatus); if (!success) { - ec = error_code(::GetLastError(), system_category()); + ec = windows_error(::GetLastError()); errs() << ToolName << ": Failed to continue debugging program: '" << ProgramToRun << "': " << ec.message() << '\n'; return -1; -- cgit v1.2.3