misc.cpp 922 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2013 Dolphin Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #include "common/common.h"
  5. #ifdef _WIN32
  6. #include <windows.h>
  7. #endif
  8. // Neither Android nor OS X support TLS
  9. #if defined(__APPLE__) || (ANDROID && __clang__)
  10. #define __thread
  11. #endif
  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. const char* GetLastErrorMsg()
  16. {
  17. static const size_t buff_size = 255;
  18. #ifdef _WIN32
  19. static __declspec(thread) char err_str[buff_size] = {};
  20. FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
  21. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  22. err_str, buff_size, nullptr);
  23. #else
  24. static __thread char err_str[buff_size] = {};
  25. // Thread safe (XSI-compliant)
  26. strerror_r(errno, err_str, buff_size);
  27. #endif
  28. return err_str;
  29. }