diff --git a/src/compat/dlfunc.c b/src/compat/dlfunc.c index 7eaf35a02..495e48836 100644 --- a/src/compat/dlfunc.c +++ b/src/compat/dlfunc.c @@ -46,7 +46,7 @@ #ifdef _WIN32 const char *dlerror() { - return get_win_error(GetLastError()); + return get_win32_error(GetLastError()); } #endif diff --git a/src/rtp/net_udp.c b/src/rtp/net_udp.c index e446e62e5..b17c6547c 100644 --- a/src/rtp/net_udp.c +++ b/src/rtp/net_udp.c @@ -237,7 +237,8 @@ void socket_error(const char *msg, ...) _vsnprintf(buffer, sizeof buffer, msg, ap); va_end(ap); - const char *errname = ws_errs[i].errno_code == 0 ? get_win_error(e) : ws_errs[i].errname; + const char *errname = ws_errs[i].errno_code == 0 ? get_win32_error(e) + : ws_errs[i].errname; log_msg(LOG_LEVEL_ERROR, "ERROR: %s, (%d - %s)\n", buffer, e, errname); #else char strerror_buf[ERRBUF_SIZE] = "unknown"; diff --git a/src/utils/net.c b/src/utils/net.c index a4aa76ad6..f0283686d 100644 --- a/src/utils/net.c +++ b/src/utils/net.c @@ -282,7 +282,8 @@ bool get_local_addresses(struct sockaddr_storage *addrs, size_t *len, int ip_ver if (dwRetVal == ERROR_NO_DATA) printf("\tNo addresses were found for the requested parameters\n"); else { - log_msg(LOG_LEVEL_ERROR, "Error: %s\n", get_win_error(dwRetVal)); + log_msg(LOG_LEVEL_ERROR, "Error: %s\n", + get_win32_error(dwRetVal)); if (pAddresses) free(pAddresses); return false; @@ -444,7 +445,7 @@ const char *ug_gai_strerror(int errcode) #ifdef _WIN32 UNUSED(errcode); // also `win_wstr_to_str(gai_strerrorW(errcode);` would work; it is localized, but with correct diacritics - return get_win_error(WSAGetLastError()); + return get_win32_error(WSAGetLastError()); #else return gai_strerror(errcode); #endif // ! defined _WIN32 diff --git a/src/utils/windows.c b/src/utils/windows.c index 0fe0f50c7..085c77c86 100644 --- a/src/utils/windows.c +++ b/src/utils/windows.c @@ -124,6 +124,8 @@ const char *hresult_to_str(HRESULT res) { } /** + * formats Win32 return codes to string + * * @param error error code (typically GetLastError()) * * @note returned error string is _not_ -terminated (stripped from FormatMessage) @@ -131,7 +133,9 @@ const char *hresult_to_str(HRESULT res) { * To achieve localized output, use languageid `MAKELANGID (LANG_NEUTRAL, SUBLANG_NEUTRAL)` and * FormatMessageW (with wchar_t), converted to UTF-8 by win_wstr_to_str. */ -const char *get_win_error(DWORD error) { +const char * +get_win32_error(DWORD error) +{ _Thread_local static char buf[1024] = "(unknown)"; if (FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, // flags NULL, // lpsource @@ -167,7 +171,7 @@ const char *win_wstr_to_str(const wchar_t *wstr) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { log_msg(LOG_LEVEL_ERROR, "win_wstr_to_str: Insufficient buffer length %zd, please report to %s!\n", sizeof res, PACKAGE_BUGREPORT); } else { - log_msg(LOG_LEVEL_ERROR, "win_wstr_to_str: %s\n", get_win_error(GetLastError())); + log_msg(LOG_LEVEL_ERROR, "win_wstr_to_str: %s\n", get_win32_error(GetLastError())); } } return res; diff --git a/src/utils/windows.h b/src/utils/windows.h index 89f474399..5daa3f465 100644 --- a/src/utils/windows.h +++ b/src/utils/windows.h @@ -83,7 +83,7 @@ void com_uninitialize(bool *com_initialized); #ifdef _WIN32 #include const char *hresult_to_str(HRESULT res); -const char *get_win_error(DWORD error); +const char *get_win32_error(DWORD error); const char *win_wstr_to_str(const wchar_t *wstr); #endif // defined _WIN32 diff --git a/src/video_capture/DirectShowGrabber.cpp b/src/video_capture/DirectShowGrabber.cpp index 8c7d20799..220e3833c 100644 --- a/src/video_capture/DirectShowGrabber.cpp +++ b/src/video_capture/DirectShowGrabber.cpp @@ -50,7 +50,7 @@ static void ErrorDescription(HRESULT hr) if(FACILITY_WINDOWS == HRESULT_FACILITY(hr)) hr = HRESULT_CODE(hr); - log_msg(LOG_LEVEL_ERROR, MOD_NAME "Error: %s\n", get_win_error(hr)); + log_msg(LOG_LEVEL_ERROR, MOD_NAME "Error: %s\n", get_win32_error(hr)); } #define DEFAULT_DEVNUM 1 diff --git a/src/video_capture/screen_win.c b/src/video_capture/screen_win.c index 3f412434c..2045a794f 100644 --- a/src/video_capture/screen_win.c +++ b/src/video_capture/screen_win.c @@ -189,7 +189,7 @@ delete_winreg_tree() return true; } MSG(ERROR, "Cannot delete " REG_FRIENDLY_NAME " from registry: %s\n", - get_win_error(err)); + get_win32_error(err)); return false; } @@ -231,7 +231,7 @@ set_key_from_str(const char *key, const char *val_c) if (res == ERROR_SUCCESS) { return true; } - MSG(ERROR, "Cannot set %s=%ld: %s\n", key, val, get_win_error(res)); + MSG(ERROR, "Cannot set %s=%ld: %s\n", key, val, get_win32_error(res)); return false; } @@ -465,7 +465,7 @@ static int vidcap_screen_win_init(struct vidcap_params *params, void **state) return VIDCAP_INIT_NOERR; } MSG(ERROR, "Elevated subshell exec failed, res = %lld (%s)\n", - ret, get_win_error(ret)); + ret, get_win32_error(ret)); return VIDCAP_INIT_FAIL; } if (strcmp(cfg, "unregister_elevated") == 0) { diff --git a/src/win32_gl_common.c b/src/win32_gl_common.c index 1ff9f1d5a..345288d27 100644 --- a/src/win32_gl_common.c +++ b/src/win32_gl_common.c @@ -192,8 +192,9 @@ failed: static void PrintError(DWORD err) { - // Display the error message and exit the process - log_msg(LOG_LEVEL_FATAL, "win32_gl_common %ld: %s\n", err, get_win_error(err)); + // Display the error message and exit the process + log_msg(LOG_LEVEL_FATAL, "win32_gl_common %ld: %s\n", err, + get_win32_error(err)); } static BOOL SetGLFormat(HDC hdc)