aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-11-28 19:40:29 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-11-28 19:40:29 +0000
commit3312b8ed3cfd4967f6bd566588d581402ad2606b (patch)
tree82584fb8c6c51d962aa6fb3aca3e0971e1b5354f
parent9d596e0e3eed6b6d244d104775df091a65aa310f (diff)
downloadpostgresql-3312b8ed3cfd4967f6bd566588d581402ad2606b.tar.gz
postgresql-3312b8ed3cfd4967f6bd566588d581402ad2606b.zip
Load netmsg.dll locally in winsock_strerror, to avoid actual and
potential problems discussed in pgsql-interfaces.
-rw-r--r--src/interfaces/libpq/fe-misc.c58
-rw-r--r--src/interfaces/libpq/libpqdll.c6
-rw-r--r--src/interfaces/libpq/win32.h7
3 files changed, 42 insertions, 29 deletions
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index 659b7fc5c83..0372da3a8b1 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -25,7 +25,7 @@
*
*
* 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 @@
#include <time.h>
#ifdef WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
#include "win32.h"
#else
#include <unistd.h>
@@ -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?
*/
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;
/* First try the "system table", this works on Win2k pro */
if (FormatMessage(
- FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
- 0, eno, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- winsock_strerror_buf, WSSE_MAXLEN, NULL
- ))
+ FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
+ 0,
+ eno,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ err_buf,
+ WSSE_MAXLEN,
+ NULL))
goto WSSE_GOODEXIT;
/* That didn't work, let's try the netmsg.dll */
- if (netmsgModule &&
- FormatMessage(
- FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_HMODULE,
- 0, eno, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- winsock_strerror_buf, WSSE_MAXLEN, NULL
- ))
- goto WSSE_GOODEXIT;
+ netmsgModule = LoadLibraryEx("netmsg.dll",
+ NULL,
+ LOAD_LIBRARY_AS_DATAFILE);
+
+ if (netmsgModule != NULL)
+ {
+ 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 */
- strcpy(winsock_strerror_buf, "Socket error, no description available.");
+ strcpy(err_buf, "Socket error, no description available.");
WSSE_GOODEXIT:
- length = strlen(winsock_strerror_buf);
- sprintf(winsock_strerror_buf + (length < WSSE_MAXLEN ? length : WSSE_MAXLEN),
- "(0x%08X)", eno);
+ length = strlen(err_buf);
+ sprintf(err_buf + (length < WSSE_MAXLEN ? length : WSSE_MAXLEN),
+ " (0x%08X)", eno);
- return winsock_strerror_buf;
+ return err_buf;
}
#endif
diff --git a/src/interfaces/libpq/libpqdll.c b/src/interfaces/libpq/libpqdll.c
index 9f9c93d2f9c..2fd6cfc7de5 100644
--- a/src/interfaces/libpq/libpqdll.c
+++ b/src/interfaces/libpq/libpqdll.c
@@ -1,8 +1,8 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-#include <winsock.h>
#include "win32.h"
+
BOOL WINAPI
DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
LPVOID lpReserved)
@@ -20,12 +20,8 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
*/
return FALSE;
}
- if (netmsgModule == NULL)
- netmsgModule = LoadLibraryEx("netmsg.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
break;
case DLL_PROCESS_DETACH:
- if (netmsgModule != NULL)
- FreeLibrary(netmsgModule);
WSACleanup();
break;
}
diff --git a/src/interfaces/libpq/win32.h b/src/interfaces/libpq/win32.h
index ac6a0ea3883..bf6d01b7ca9 100644
--- a/src/interfaces/libpq/win32.h
+++ b/src/interfaces/libpq/win32.h
@@ -31,9 +31,6 @@
#define EINPROGRESS WSAEINPROGRESS
/*
- * Windows network messaging stuff:
+ * support for handling Windows Socket errors
*/
-static HINSTANCE netmsgModule = NULL;
-
-static char winsock_strerror_buf[512];
-const char *winsock_strerror(DWORD eno);
+extern const char *winsock_strerror(int eno);