From: Viktor Szakats Date: Mon, 6 Oct 2025 01:02:24 +0000 (+0200) Subject: windows: use consistent format when showing error codes X-Git-Tag: rc-8_17_0-2~231 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=51b85bdc6cd48a55c75b03afcf1f057839564ae8;p=thirdparty%2Fcurl.git windows: use consistent format when showing error codes For `GetLastError()` and `SECURITY_STATUS`: 0x-prefixed, 8-digit, lowercase, hex: 0x1234abcd Also: say `GetLastError()` instead of `errno` in one message. Closes #18877 --- diff --git a/lib/curlx/winapi.c b/lib/curlx/winapi.c index 6d94733bed..de1218cec7 100644 --- a/lib/curlx/winapi.c +++ b/lib/curlx/winapi.c @@ -103,7 +103,7 @@ const char *curlx_winapi_strerror(DWORD err, char *buf, size_t buflen) #endif /* some GCC compilers cause false positive warnings if we allow this warning */ - SNPRINTF(buf, buflen, "Unknown error %lu (0x%08lX)", err, err); + SNPRINTF(buf, buflen, "Unknown error %lu (0x%08lx)", err, err); #if defined(__GNUC__) && __GNUC__ >= 7 #pragma GCC diagnostic pop #endif diff --git a/lib/strerror.c b/lib/strerror.c index 8d22ac9b34..5b82d7f965 100644 --- a/lib/strerror.c +++ b/lib/strerror.c @@ -656,7 +656,7 @@ const char *Curl_sspi_strerror(SECURITY_STATUS err, char *buf, size_t buflen) if(err == SEC_E_ILLEGAL_MESSAGE) { curl_msnprintf(buf, buflen, - "SEC_E_ILLEGAL_MESSAGE (0x%08lX) - This error usually " + "SEC_E_ILLEGAL_MESSAGE (0x%08lx) - This error usually " "occurs when a fatal SSL/TLS alert is received (e.g. " "handshake failed). More detail may be available in " "the Windows System event log.", err); @@ -664,9 +664,9 @@ const char *Curl_sspi_strerror(SECURITY_STATUS err, char *buf, size_t buflen) else { char msgbuf[256]; if(curlx_get_winapi_error((DWORD)err, msgbuf, sizeof(msgbuf))) - curl_msnprintf(buf, buflen, "%s (0x%08lX) - %s", txt, err, msgbuf); + curl_msnprintf(buf, buflen, "%s (0x%08lx) - %s", txt, err, msgbuf); else - curl_msnprintf(buf, buflen, "%s (0x%08lX)", txt, err); + curl_msnprintf(buf, buflen, "%s (0x%08lx)", txt, err); } #else diff --git a/lib/vauth/ntlm_sspi.c b/lib/vauth/ntlm_sspi.c index dff5fe8747..d421879161 100644 --- a/lib/vauth/ntlm_sspi.c +++ b/lib/vauth/ntlm_sspi.c @@ -313,7 +313,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data, &type_3_desc, &attrs, NULL); if(status != SEC_E_OK) { - infof(data, "NTLM handshake failure (type-3 message): Status=%lx", + infof(data, "NTLM handshake failure (type-3 message): Status=0x%08lx", status); if(status == SEC_E_INSUFFICIENT_MEMORY) diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c index bf68321afe..c0e96c93bf 100644 --- a/lib/vtls/schannel.c +++ b/lib/vtls/schannel.c @@ -659,7 +659,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, cert_showfilename_error); else failf(data, "schannel: Failed to import cert file %s, " - "last error is 0x%lx", + "last error is 0x%08lx", cert_showfilename_error, errorcode); return CURLE_SSL_CERTPROBLEM; } @@ -678,7 +678,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, if(!client_certs[0]) { failf(data, "schannel: Failed to get certificate from file %s" - ", last error is 0x%lx", + ", last error is 0x%08lx", cert_showfilename_error, GetLastError()); CertCloseStore(cert_store, 0); return CURLE_SSL_CERTPROBLEM; @@ -700,7 +700,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, char *path_utf8 = curlx_convert_tchar_to_UTF8(cert_store_path); failf(data, "schannel: Failed to open cert store %lx %s, " - "last error is 0x%lx", + "last error is 0x%08lx", cert_store_name, (path_utf8 ? path_utf8 : "(unknown)"), GetLastError()); diff --git a/src/tool_doswin.c b/src/tool_doswin.c index 51b6f34101..5cf58405b3 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -871,7 +871,7 @@ curl_socket_t win32_stdin_read_thread(void) 0, FALSE, DUPLICATE_SAME_ACCESS); if(!r) { - errorf("DuplicateHandle error: %08lx", GetLastError()); + errorf("DuplicateHandle error: 0x%08lx", GetLastError()); break; } @@ -882,7 +882,7 @@ curl_socket_t win32_stdin_read_thread(void) stdin_thread = CreateThread(NULL, 0, win_stdin_thread_func, tdata, 0, NULL); if(!stdin_thread) { - errorf("CreateThread error: %08lx", GetLastError()); + errorf("CreateThread error: 0x%08lx", GetLastError()); break; } @@ -908,7 +908,7 @@ curl_socket_t win32_stdin_read_thread(void) /* Set the stdin handle to read from the socket. */ if(SetStdHandle(STD_INPUT_HANDLE, (HANDLE)socket_r) == 0) { - errorf("SetStdHandle error: %08lx", GetLastError()); + errorf("SetStdHandle error: 0x%08lx", GetLastError()); break; } diff --git a/src/tool_filetime.c b/src/tool_filetime.c index afd84c0138..6dc2fbbe42 100644 --- a/src/tool_filetime.c +++ b/src/tool_filetime.c @@ -62,13 +62,13 @@ int getfiletime(const char *filename, curl_off_t *stamp) } } else { - warnf("Failed to get filetime: GetFileTime failed: GetLastError %lu", + warnf("Failed to get filetime: GetFileTime failed: GetLastError 0x%08lx", GetLastError()); } CloseHandle(hfile); } else if(GetLastError() != ERROR_FILE_NOT_FOUND) { - warnf("Failed to get filetime: CreateFile failed: GetLastError %lu", + warnf("Failed to get filetime: CreateFile failed: GetLastError 0x%08lx", GetLastError()); } #else @@ -118,14 +118,14 @@ void setfiletime(curl_off_t filetime, const char *filename) ft.dwHighDateTime = (DWORD)(converted >> 32); if(!SetFileTime(hfile, NULL, &ft, &ft)) { warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T - " on outfile: SetFileTime failed: GetLastError %lu", + " on outfile: SetFileTime failed: GetLastError 0x%08lx", filetime, GetLastError()); } CloseHandle(hfile); } else { warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T - " on outfile: CreateFile failed: GetLastError %lu", + " on outfile: CreateFile failed: GetLastError 0x%08lx", filetime, GetLastError()); } diff --git a/tests/libtest/lib3026.c b/tests/libtest/lib3026.c index 167fdd4d33..75d419cb58 100644 --- a/tests/libtest/lib3026.c +++ b/tests/libtest/lib3026.c @@ -59,7 +59,8 @@ static CURLcode test_lib3026(const char *URL) results[i] = CURL_LAST; /* initialize with invalid value */ th = CreateThread(NULL, 0, t3026_run_thread, &results[i], 0, NULL); if(!th) { - curl_mfprintf(stderr, "%s:%d Couldn't create thread, errno %lu\n", + curl_mfprintf(stderr, "%s:%d Couldn't create thread, " + "GetLastError 0x%08lx\n", __FILE__, __LINE__, GetLastError()); tid_count = i; test_failure = TEST_ERR_MAJOR_BAD;