Skip to content

Commit

Permalink
coap_socket_strerror: For Windows, return ascii readable
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed Dec 18, 2024
1 parent a87fb0c commit b7eee79
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/coap_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2026,28 +2026,17 @@ coap_io_pending_lkd(coap_context_t *context) {
return 0;
}

#ifdef _WIN32
const char *
coap_socket_format_errno(int error) {
static char szError[256];
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, (DWORD)error, MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT), (LPSTR)szError, (DWORD)sizeof(szError),
NULL) == 0)
strcpy(szError, "Unknown error");
return szError;
return strerror(error);
}

#ifdef _WIN32
const char *
coap_socket_strerror(void) {
return coap_socket_format_errno(WSAGetLastError());
}
#else /* _WIN32 */
const char *
coap_socket_format_errno(int error) {
return strerror(error);
}
const char *
coap_socket_strerror(void) {
return coap_socket_format_errno(errno);
}
Expand Down

0 comments on commit b7eee79

Please sign in to comment.