Status.cxx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
  3. #include "kwsysPrivate.h"
  4. #include KWSYS_HEADER(Status.hxx)
  5. // Work-around CMake dependency scanning limitation. This must
  6. // duplicate the above list of headers.
  7. #if 0
  8. # include "Status.hxx.in"
  9. #endif
  10. #include <cerrno>
  11. #include <cstring>
  12. #include <string>
  13. #if defined(_WIN32)
  14. # include <windows.h>
  15. #endif
  16. namespace KWSYS_NAMESPACE {
  17. Status Status::POSIX_errno()
  18. {
  19. return Status::POSIX(errno);
  20. }
  21. #ifdef _WIN32
  22. Status Status::Windows_GetLastError()
  23. {
  24. return Status::Windows(GetLastError());
  25. }
  26. #endif
  27. std::string Status::GetString() const
  28. {
  29. std::string err;
  30. switch (this->Kind_) {
  31. case Kind::Success:
  32. err = "Success";
  33. break;
  34. case Kind::POSIX:
  35. err = strerror(this->POSIX_);
  36. break;
  37. #ifdef _WIN32
  38. case Kind::Windows: {
  39. LPSTR message = NULL;
  40. DWORD size = FormatMessageA(
  41. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
  42. FORMAT_MESSAGE_IGNORE_INSERTS,
  43. NULL, this->Windows_, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  44. (LPSTR)&message, 0, NULL);
  45. err = std::string(message, size);
  46. LocalFree(message);
  47. } break;
  48. #endif
  49. }
  50. return err;
  51. }
  52. } // namespace KWSYS_NAMESPACE