renamed get_win_error->get_win32_error

it formats win32 errors, but not HRESULT in general
This commit is contained in:
Martin Pulec
2023-10-27 12:16:48 +02:00
parent 9ac5e932c5
commit 8b412140d7
8 changed files with 20 additions and 13 deletions

View File

@@ -46,7 +46,7 @@
#ifdef _WIN32
const char *dlerror() {
return get_win_error(GetLastError());
return get_win32_error(GetLastError());
}
#endif

View File

@@ -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";

View File

@@ -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

View File

@@ -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_ <NL>-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;

View File

@@ -83,7 +83,7 @@ void com_uninitialize(bool *com_initialized);
#ifdef _WIN32
#include <winerror.h>
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

View File

@@ -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

View File

@@ -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) {

View File

@@ -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)