diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-04-02 09:45:33 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-04-02 09:45:33 (GMT) |
commit | 4616d563cc45f6587cd89ceafe025fb0a7c3f5d3 (patch) | |
tree | baa804a74e866af1714879cd34feea75a7700cda /win | |
parent | 00ecea59b1312bc698ecae83fe7ba38e9641d6be (diff) | |
parent | fc2795b65712079b300f7e819aeb48aca040dfbf (diff) | |
download | tcl-4616d563cc45f6587cd89ceafe025fb0a7c3f5d3.zip tcl-4616d563cc45f6587cd89ceafe025fb0a7c3f5d3.tar.gz tcl-4616d563cc45f6587cd89ceafe025fb0a7c3f5d3.tar.bz2 |
[Bug 3508771] load tclreg.dll in cygwin tclsh
Implement TclWinGetTclInstance, TclpGetTZName,
and various others for Cygwin
Diffstat (limited to 'win')
-rw-r--r-- | win/tclWinError.c | 64 | ||||
-rw-r--r-- | win/tclWinSock.c | 42 |
2 files changed, 64 insertions, 42 deletions
diff --git a/win/tclWinError.c b/win/tclWinError.c index 1b59dbe..969780d 100644 --- a/win/tclWinError.c +++ b/win/tclWinError.c @@ -11,15 +11,6 @@ */ #include "tclInt.h" - -#ifndef WSAEWOULDBLOCK -# define WSAEWOULDBLOCK 10035L -#endif - -#ifndef __WIN32__ -# define DWORD unsigned int -#endif - /* * The following table contains the mapping from Win32 errors to errno errors. */ @@ -340,6 +331,11 @@ static const unsigned char wsaErrorTable[] = { EREMOTE /* WSAEREMOTE */ }; +#ifdef __CYGWIN__ +# include <windows.h> +# define DWORD unsigned int +#endif + /* *---------------------------------------------------------------------- * @@ -361,40 +357,66 @@ TclWinConvertError( DWORD errCode) /* Win32 error code. */ { if (errCode >= sizeof(errorTable)/sizeof(errorTable[0])) { - Tcl_SetErrno(EINVAL); + errCode -= WSAEWOULDBLOCK; + if (errCode >= sizeof(wsaErrorTable)/sizeof(wsaErrorTable[0])) { + Tcl_SetErrno(errorTable[1]); + } else { + Tcl_SetErrno(wsaErrorTable[errCode]); + } } else { 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, ...) { - errCode -= WSAEWOULDBLOCK; - if (errCode >= sizeof(wsaErrorTable)/sizeof(wsaErrorTable[0])) { - Tcl_SetErrno(EINVAL); +#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(wsaErrorTable[errCode]); + vfprintf(stderr, format, argList); + fprintf(stderr, "\n"); + fflush(stderr); } } - +#endif /* * Local Variables: * mode: c diff --git a/win/tclWinSock.c b/win/tclWinSock.c index 60cc313..74c7245 100644 --- a/win/tclWinSock.c +++ b/win/tclWinSock.c @@ -328,19 +328,19 @@ InitSockets(void) err = WSAStartup((WORD)WSA_VERSION_REQD, &wsaData); if (err != 0) { - TclWinConvertWSAError(err); + TclWinConvertError(err); goto initFailure; } /* - * Note the byte positions are swapped for the comparison, so that + * Note the byte positions ae swapped for the comparison, so that * 0x0002 (2.0, MAKEWORD(2,0)) doesn't look less than 0x0101 (1.1). * We want the comparison to be 0x0200 < 0x0101. */ if (MAKEWORD(HIBYTE(wsaData.wVersion), LOBYTE(wsaData.wVersion)) < MAKEWORD(WSA_VERSION_MINOR, WSA_VERSION_MAJOR)) { - TclWinConvertWSAError(WSAVERNOTSUPPORTED); + TclWinConvertError(WSAVERNOTSUPPORTED); WSACleanup(); goto initFailure; } @@ -861,7 +861,7 @@ TcpCloseProc( */ if (closesocket(infoPtr->sockets->fd) == SOCKET_ERROR) { - TclWinConvertWSAError((DWORD) WSAGetLastError()); + TclWinConvertError((DWORD) WSAGetLastError()); errorCode = Tcl_GetErrno(); } } @@ -923,7 +923,7 @@ TcpClose2Proc( return TCL_ERROR; } if (shutdown(infoPtr->sockets->fd,sd) == SOCKET_ERROR) { - TclWinConvertWSAError((DWORD) WSAGetLastError()); + TclWinConvertError((DWORD) WSAGetLastError()); errorCode = Tcl_GetErrno(); } @@ -1041,7 +1041,7 @@ CreateSocket( for (addrPtr = addrlist; addrPtr != NULL; addrPtr = addrPtr->ai_next) { sock = socket(addrPtr->ai_family, SOCK_STREAM, 0); if (sock == INVALID_SOCKET) { - TclWinConvertWSAError((DWORD) WSAGetLastError()); + TclWinConvertError((DWORD) WSAGetLastError()); continue; } @@ -1082,7 +1082,7 @@ CreateSocket( if (bind(sock, addrPtr->ai_addr, addrPtr->ai_addrlen) == SOCKET_ERROR) { - TclWinConvertWSAError((DWORD) WSAGetLastError()); + TclWinConvertError((DWORD) WSAGetLastError()); closesocket(sock); continue; } @@ -1105,7 +1105,7 @@ CreateSocket( */ if (listen(sock, SOMAXCONN) == SOCKET_ERROR) { - TclWinConvertWSAError((DWORD) WSAGetLastError()); + TclWinConvertError((DWORD) WSAGetLastError()); closesocket(sock); continue; } @@ -1150,7 +1150,7 @@ CreateSocket( sock = socket(myaddrPtr->ai_family, SOCK_STREAM, 0); if (sock == INVALID_SOCKET) { - TclWinConvertWSAError((DWORD) WSAGetLastError()); + TclWinConvertError((DWORD) WSAGetLastError()); continue; } @@ -1173,7 +1173,7 @@ CreateSocket( if (bind(sock, myaddrPtr->ai_addr, myaddrPtr->ai_addrlen) == SOCKET_ERROR) { - TclWinConvertWSAError((DWORD) WSAGetLastError()); + TclWinConvertError((DWORD) WSAGetLastError()); goto looperror; } /* @@ -1183,7 +1183,7 @@ CreateSocket( if (async) { if (ioctlsocket(sock, (long) FIONBIO, &flag) == SOCKET_ERROR) { - TclWinConvertWSAError((DWORD) WSAGetLastError()); + TclWinConvertError((DWORD) WSAGetLastError()); goto looperror; } } @@ -1194,7 +1194,7 @@ CreateSocket( if (connect(sock, addrPtr->ai_addr, addrPtr->ai_addrlen) == SOCKET_ERROR) { - TclWinConvertWSAError((DWORD) WSAGetLastError()); + TclWinConvertError((DWORD) WSAGetLastError()); if (Tcl_GetErrno() != EAGAIN) { goto looperror; } @@ -1809,7 +1809,7 @@ TcpInputProc( */ if ((infoPtr->flags & SOCKET_ASYNC) || (error != WSAEWOULDBLOCK)) { - TclWinConvertWSAError(error); + TclWinConvertError(error); *errorCodePtr = Tcl_GetErrno(); bytesRead = -1; break; @@ -1918,7 +1918,7 @@ TcpOutputProc( break; } } else { - TclWinConvertWSAError(error); + TclWinConvertError(error); *errorCodePtr = Tcl_GetErrno(); bytesWritten = -1; break; @@ -1998,7 +1998,7 @@ TcpSetOptionProc( rtn = setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (const char *) &val, sizeof(BOOL)); if (rtn != 0) { - TclWinConvertWSAError(WSAGetLastError()); + TclWinConvertError(WSAGetLastError()); if (interp) { Tcl_AppendResult(interp, "couldn't set socket option: ", Tcl_PosixError(interp), NULL); @@ -2019,7 +2019,7 @@ TcpSetOptionProc( rtn = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *) &val, sizeof(BOOL)); if (rtn != 0) { - TclWinConvertWSAError(WSAGetLastError()); + TclWinConvertError(WSAGetLastError()); if (interp) { Tcl_AppendResult(interp, "couldn't set socket option: ", Tcl_PosixError(interp), NULL); @@ -2103,7 +2103,7 @@ TcpGetOptionProc( err = WSAGetLastError(); } if (err) { - TclWinConvertWSAError(err); + TclWinConvertError(err); Tcl_DStringAppend(dsPtr, Tcl_ErrnoMsg(Tcl_GetErrno()), -1); } return TCL_OK; @@ -2144,7 +2144,7 @@ TcpGetOptionProc( */ if (len) { - TclWinConvertWSAError((DWORD) WSAGetLastError()); + TclWinConvertError((DWORD) WSAGetLastError()); if (interp) { Tcl_AppendResult(interp, "can't get peername: ", Tcl_PosixError(interp), NULL); @@ -2210,7 +2210,7 @@ TcpGetOptionProc( } } else { if (interp) { - TclWinConvertWSAError((DWORD) WSAGetLastError()); + TclWinConvertError((DWORD) WSAGetLastError()); Tcl_AppendResult(interp, "can't get sockname: ", Tcl_PosixError(interp), NULL); } @@ -2518,7 +2518,7 @@ SocketProc( */ if (error != ERROR_SUCCESS) { - TclWinConvertWSAError((DWORD) error); + TclWinConvertError((DWORD) error); infoPtr->lastError = Tcl_GetErrno(); } } @@ -2526,7 +2526,7 @@ SocketProc( if (infoPtr->flags & SOCKET_ASYNC_CONNECT) { infoPtr->flags &= ~(SOCKET_ASYNC_CONNECT); if (error != ERROR_SUCCESS) { - TclWinConvertWSAError((DWORD) error); + TclWinConvertError((DWORD) error); infoPtr->lastError = Tcl_GetErrno(); } infoPtr->readyEvents |= FD_WRITE; |