summaryrefslogtreecommitdiffstats
path: root/win/tclWinError.c
diff options
context:
space:
mode:
Diffstat (limited to 'win/tclWinError.c')
-rw-r--r--win/tclWinError.c53
1 files changed, 34 insertions, 19 deletions
diff --git a/win/tclWinError.c b/win/tclWinError.c
index a74d2e2..63e9598 100644
--- a/win/tclWinError.c
+++ b/win/tclWinError.c
@@ -11,13 +11,11 @@
*/
#include "tclInt.h"
-#include "tclPort.h"
-
/*
* The following table contains the mapping from Win32 errors to errno errors.
*/
-static CONST unsigned char errorTable[] = {
+static const unsigned char errorTable[] = {
0,
EINVAL, /* ERROR_INVALID_FUNCTION 1 */
ENOENT, /* ERROR_FILE_NOT_FOUND 2 */
@@ -293,8 +291,8 @@ static CONST unsigned char errorTable[] = {
* errno errors.
*/
-static CONST int wsaErrorTable[] = {
- EWOULDBLOCK, /* WSAEWOULDBLOCK */
+static const unsigned char wsaErrorTable[] = {
+ EAGAIN, /* WSAEWOULDBLOCK */
EINPROGRESS, /* WSAEINPROGRESS */
EALREADY, /* WSAEALREADY */
ENOTSOCK, /* WSAENOTSOCK */
@@ -364,39 +362,56 @@ TclWinConvertError(
Tcl_SetErrno(errorTable[errCode]);
}
}
-
+
+#ifdef __CYGWIN__
/*
*----------------------------------------------------------------------
*
- * TclWinConvertWSAError --
+ * tclWinDebugPanic --
*
- * This routine converts a WinSock error into an errno value.
+ * Display a message. If a debugger is present, present it directly to
+ * the debugger, otherwise send it to stderr.
*
* Results:
* None.
*
* Side effects:
- * Sets the errno global variable.
+ * None.
*
*----------------------------------------------------------------------
*/
void
-TclWinConvertWSAError(
- DWORD errCode) /* Win32 error code. */
+tclWinDebugPanic(
+ const char *format, ...)
{
- if (errCode >= sizeof(errorTable)/sizeof(errorTable[0])) {
- errCode -= WSAEWOULDBLOCK;
- if (errCode >= sizeof(wsaErrorTable)/sizeof(wsaErrorTable[0])) {
- Tcl_SetErrno(errorTable[1]);
- } else {
- Tcl_SetErrno(wsaErrorTable[errCode]);
+#define TCL_MAX_WARN_LEN 1024
+ va_list argList;
+ va_start(argList, format);
+
+ if (IsDebuggerPresent()) {
+ WCHAR msgString[TCL_MAX_WARN_LEN];
+ char buf[TCL_MAX_WARN_LEN * TCL_UTF_MAX];
+
+ vsnprintf(buf, sizeof(buf), format, argList);
+ msgString[TCL_MAX_WARN_LEN-1] = L'\0';
+ MultiByteToWideChar(CP_UTF8, 0, buf, -1, msgString, TCL_MAX_WARN_LEN);
+
+ /*
+ * Truncate MessageBox string if it is too long to not overflow the buffer.
+ */
+
+ if (msgString[TCL_MAX_WARN_LEN-1] != L'\0') {
+ memcpy(msgString + (TCL_MAX_WARN_LEN - 5), L" ...", 5 * sizeof(WCHAR));
}
+ OutputDebugStringW(msgString);
} else {
- Tcl_SetErrno(errorTable[errCode]);
+ vfprintf(stderr, format, argList);
+ fprintf(stderr, "\n");
+ fflush(stderr);
}
}
-
+#endif
/*
* Local Variables:
* mode: c