misc.cpp 870 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cstddef>
  5. #ifdef _WIN32
  6. #include <windows.h>
  7. #else
  8. #include <cerrno>
  9. #include <cstring>
  10. #endif
  11. #include "common/common_funcs.h"
  12. // Generic function to get last error message.
  13. // Call directly after the command or use the error num.
  14. // This function might change the error code.
  15. std::string GetLastErrorMsg() {
  16. static const size_t buff_size = 255;
  17. char err_str[buff_size];
  18. #ifdef _WIN32
  19. FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
  20. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr);
  21. #else
  22. // Thread safe (XSI-compliant)
  23. strerror_r(errno, err_str, buff_size);
  24. #endif
  25. return std::string(err_str, buff_size);
  26. }