← Commit list

4890074e68

dEajL3kA
dEajL3kA
2026-01-21
SUCCESS Duration: 467s

Subject

winapi: use FormatMessageA instead of FormatMessageW

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

lib/curlx/winapi.c+14 -17
@@ -39,30 +39,27 @@
const char *curlx_get_winapi_error(DWORD err, char *buf, size_t buflen)
{
char *p;
- wchar_t wbuf[256];
- DWORD wlen;
if(!buflen)
return NULL;
- *buf = '\0';
- *wbuf = L'\0';
-
/* We return the local codepage version of the error string because if it is
output to the user's terminal it will likely be with functions which
expect the local codepage (eg fprintf, failf, infof). */
- wlen = FormatMessageW((FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS), NULL, err,
- LANG_NEUTRAL, wbuf, CURL_ARRAYSIZE(wbuf), NULL);
- if(wlen && !wcstombs_s(NULL, buf, buflen, wbuf, wlen)) {
- /* Truncate multiple lines */
- p = strchr(buf, '\n');
- if(p) {
- if(p > buf && *(p - 1) == '\r')
- *(p - 1) = '\0';
- else
- *p = '\0';
- }
+ if(!FormatMessageA((FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS), NULL, err,
+ LANG_NEUTRAL, buf, (DWORD)buflen, NULL)) {
+ *buf = '\0';
+ return NULL;
+ }
+
+ /* Truncate multiple lines */
+ p = strchr(buf, '\n');
+ if(p) {
+ if(p > buf && *(p - 1) == '\r')
+ *(p - 1) = '\0';
+ else
+ *p = '\0';
}
return *buf ? buf : NULL;