On Windows strerror() doesn't work with winsocket error codes (returned by WSAGetLastError()). This patch changes the way BasicUsageEnvironment0::setResultMsg() gets error message on Windows, now it gets it using FormatMessage() with a backup solution of simply providing error code in the message (FormatMessage() apparently can fail too). --- BasicUsageEnvironment/BasicUsageEnvironment0.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
-- Stas Tsymbalov TrueConf LLC http://trueconf.com/
diff --git a/BasicUsageEnvironment/BasicUsageEnvironment0.cpp b/BasicUsageEnvironment/BasicUsageEnvironment0.cpp index 7f3aa3b..9d2fdf4 100644 --- a/BasicUsageEnvironment/BasicUsageEnvironment0.cpp +++ b/BasicUsageEnvironment/BasicUsageEnvironment0.cpp @@ -20,6 +20,10 @@ along with this library; if not, write to the Free Software Foundation, Inc., #include "BasicUsageEnvironment0.hh" #include <stdio.h> +#if defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_WCE) +#define snprintf _snprintf +#endif + ////////// BasicUsageEnvironment ////////// BasicUsageEnvironment0::BasicUsageEnvironment0(TaskScheduler& taskScheduler) @@ -62,8 +66,18 @@ void BasicUsageEnvironment0::setResultMsg(MsgString msg1, MsgString msg2, void BasicUsageEnvironment0::setResultErrMsg(MsgString msg, int err) { setResultMsg(msg); -#ifndef _WIN32_WCE - appendToResultMsg(strerror(err == 0 ? getErrno() : err)); + if (err == 0) err = getErrno(); +#if defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_WCE) + char errMsg[RESULT_MSG_BUFFER_MAX] = "\0"; + if (0 != FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, errMsg, sizeof(errMsg)/sizeof(errMsg[0]), NULL)) { + // Remove all trailing '\r', '\n' and '.' + for (char* p = errMsg + strlen(errMsg); p != errMsg && (*p == '\r' || *p == '\n' || *p == '.' || *p == '\0'); --p) + *p = '\0'; + } else + snprintf(errMsg, sizeof(errMsg)/sizeof(errMsg[0]), "error %d", err); + appendToResultMsg(errMsg); +#else + appendToResultMsg(strerror(err)); #endif }
_______________________________________________ live-devel mailing list live-devel@lists.live555.com http://lists.live555.com/mailman/listinfo/live-devel