diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2023-01-27 13:59:57 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2023-05-03 23:11:34 -0400 |
commit | b9c0424514183df9c26193837f8b5aedaf6ac34f (patch) | |
tree | da115c32f2883c4d960815ed36eda10137a00246 /src/log.c | |
parent | 7553c09da980845eb5b03d286ee4c4bf247e6eae (diff) | |
download | lighttpd-git-b9c0424514183df9c26193837f8b5aedaf6ac34f.tar.gz |
[core] _WIN32 log_perror() with GetLastError()
Diffstat (limited to 'src/log.c')
-rw-r--r-- | src/log.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -269,6 +269,24 @@ log_error_write (const log_error_st * const errh, buffer * const restrict b) } +#ifdef _WIN32 +static void +log_error_append_winerror (buffer * const b, DWORD dwMessageId) +{ + if (0 == dwMessageId) return; /* The operation completed successfully. */ + TCHAR lpMsgBuf[1024]; + lpMsgBuf[0] = '\0'; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, dwMessageId, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)lpMsgBuf, sizeof(lpMsgBuf)/sizeof(TCHAR), NULL); + size_t len = strlen(lpMsgBuf); + if (len && lpMsgBuf[len-1] == '\n') --len; + if (len && lpMsgBuf[len-1] == '\r') --len; + buffer_append_str2(b, CONST_STR_LEN(": "), lpMsgBuf, len); +} +#endif + + __attribute_noinline__ static void log_error_append_strerror (buffer * const b, const int errnum) @@ -295,8 +313,17 @@ log_error_va_list_impl (const log_error_st *errh, if (NULL == b) return; /*(errno not modified if errh->fd == -1)*/ log_buffer_vsprintf(b, fmt, ap); + #ifdef _WIN32 + switch (perr) { + case 0: default: break; + case 1: log_error_append_winerror(b, GetLastError()); + if (errnum) log_error_append_strerror(b, errnum); + break; + } + #else if (perr) log_error_append_strerror(b, errnum); + #endif log_error_write(errh, b); |