WINPR_API void winpr_backtrace_free(void* buffer);
WINPR_API char** winpr_backtrace_symbols(void* buffer, size_t* used);
WINPR_API void winpr_backtrace_symbols_fd(void* buffer, int fd);
+WINPR_API char* winpr_strerror(DWORD dw, char* dmsg, size_t size);
#ifdef __cplusplus
}
winpr_backtrace_free(stack);
}
+char* winpr_strerror(DWORD dw, char* dmsg, size_t size) {
+ LPTSTR msg = NULL;
+ DWORD rc;
+
+#if defined(_WIN32)
+ rc = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, dw, 0, (LPTSTR)&msg, 0, NULL);
+ if (rc) {
+#if defined(UNICODE)
+ WideCharToMultiByte(CP_ACP, 0, msg, rc, dmsg, size - 1, NULL, NULL);
+#else
+ memcpy(dmsg, msg, min(rc, size - 1));
+#endif
+ dmsg[min(rc, size - 1)] = 0;
+ LocalFree(msg);
+ } else {
+ _snprintf(dmsg, size, "FAILURE: %08X", GetLastError());
+ }
+#else
+ _snprintf(dmsg, size, "%s", strerror(dw));
+#endif
+
+ return dmsg;
+}