misc.cpp 1005 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 "common/common_funcs.h"
  5. #ifdef _WIN32
  6. #include <windows.h>
  7. #else
  8. #include <string.h>
  9. #endif
  10. // Neither Android nor OS X support TLS
  11. #if defined(__APPLE__) || (ANDROID && __clang__)
  12. #define __thread
  13. #endif
  14. // Generic function to get last error message.
  15. // Call directly after the command or use the error num.
  16. // This function might change the error code.
  17. const char* GetLastErrorMsg()
  18. {
  19. static const size_t buff_size = 255;
  20. #ifdef _WIN32
  21. static __declspec(thread) char err_str[buff_size] = {};
  22. FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
  23. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  24. err_str, buff_size, nullptr);
  25. #else
  26. static __thread char err_str[buff_size] = {};
  27. // Thread safe (XSI-compliant)
  28. strerror_r(errno, err_str, buff_size);
  29. #endif
  30. return err_str;
  31. }