Commit 3312b8ed authored by Tom Lane's avatar Tom Lane

Load netmsg.dll locally in winsock_strerror, to avoid actual and

potential problems discussed in pgsql-interfaces.
parent 9d596e0e
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.63 2001/11/27 18:21:51 tgl Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.64 2001/11/28 19:40:29 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include <time.h> #include <time.h>
#ifdef WIN32 #ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "win32.h" #include "win32.h"
#else #else
#include <unistd.h> #include <unistd.h>
...@@ -858,41 +860,59 @@ libpq_gettext(const char *msgid) ...@@ -858,41 +860,59 @@ libpq_gettext(const char *msgid)
* If you can verify this working on win9x or have a solution, let us know, ok? * If you can verify this working on win9x or have a solution, let us know, ok?
*/ */
const char * const char *
winsock_strerror(DWORD eno) winsock_strerror(int eno)
{ {
#define WSSE_MAXLEN (sizeof(winsock_strerror_buf)-1-12) /* 12 == "(0x00000000)" */ static char err_buf[512];
#define WSSE_MAXLEN (sizeof(err_buf)-1-13) /* 13 == " (0x00000000)" */
HINSTANCE netmsgModule;
int length; int length;
/* First try the "system table", this works on Win2k pro */ /* First try the "system table", this works on Win2k pro */
if (FormatMessage( if (FormatMessage(
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
0, eno, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 0,
winsock_strerror_buf, WSSE_MAXLEN, NULL eno,
)) MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
err_buf,
WSSE_MAXLEN,
NULL))
goto WSSE_GOODEXIT; goto WSSE_GOODEXIT;
/* That didn't work, let's try the netmsg.dll */ /* That didn't work, let's try the netmsg.dll */
if (netmsgModule && netmsgModule = LoadLibraryEx("netmsg.dll",
FormatMessage( NULL,
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_HMODULE, LOAD_LIBRARY_AS_DATAFILE);
0, eno, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
winsock_strerror_buf, WSSE_MAXLEN, NULL if (netmsgModule != NULL)
)) {
goto WSSE_GOODEXIT; if (FormatMessage(
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_HMODULE,
netmsgModule,
eno,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
err_buf,
WSSE_MAXLEN,
NULL))
{
FreeLibrary(netmsgModule);
goto WSSE_GOODEXIT;
}
FreeLibrary(netmsgModule);
}
/* Everything failed, just tell the user that we don't know the desc */ /* Everything failed, just tell the user that we don't know the desc */
strcpy(winsock_strerror_buf, "Socket error, no description available."); strcpy(err_buf, "Socket error, no description available.");
WSSE_GOODEXIT: WSSE_GOODEXIT:
length = strlen(winsock_strerror_buf); length = strlen(err_buf);
sprintf(winsock_strerror_buf + (length < WSSE_MAXLEN ? length : WSSE_MAXLEN), sprintf(err_buf + (length < WSSE_MAXLEN ? length : WSSE_MAXLEN),
"(0x%08X)", eno); " (0x%08X)", eno);
return winsock_strerror_buf; return err_buf;
} }
#endif #endif
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#include <winsock.h>
#include "win32.h" #include "win32.h"
BOOL WINAPI BOOL WINAPI
DllMain(HINSTANCE hinstDLL, DWORD fdwReason, DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
LPVOID lpReserved) LPVOID lpReserved)
...@@ -20,12 +20,8 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason, ...@@ -20,12 +20,8 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
*/ */
return FALSE; return FALSE;
} }
if (netmsgModule == NULL)
netmsgModule = LoadLibraryEx("netmsg.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
break; break;
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
if (netmsgModule != NULL)
FreeLibrary(netmsgModule);
WSACleanup(); WSACleanup();
break; break;
} }
......
...@@ -31,9 +31,6 @@ ...@@ -31,9 +31,6 @@
#define EINPROGRESS WSAEINPROGRESS #define EINPROGRESS WSAEINPROGRESS
/* /*
* Windows network messaging stuff: * support for handling Windows Socket errors
*/ */
static HINSTANCE netmsgModule = NULL; extern const char *winsock_strerror(int eno);
static char winsock_strerror_buf[512];
const char *winsock_strerror(DWORD eno);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment