Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ee0ef05

Browse files
committed
Hello, i just reviewed the win32 errno patch and i saw that maybe i didn't
really played it totally safe in my last suggestion, the system table might pick up the msg but not the netmsg.dll, so better try both. I also added a hex printout of the "errno" appended to all messages, that's nicer. If anyone hate my coding style, or that i'm using goto constructs, just tell me, and i'll rework it into a nested if () thing. Magnus Naeslund(f)
1 parent 6c91eef commit ee0ef05

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

src/interfaces/libpq/fe-misc.c

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
*
2727
* IDENTIFICATION
28-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.54 2001/08/21 20:39:54 momjian Exp $
28+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.55 2001/09/06 02:52:00 momjian Exp $
2929
*
3030
*-------------------------------------------------------------------------
3131
*/
@@ -855,23 +855,46 @@ libpq_gettext(const char *msgid)
855855
#ifdef WIN32
856856
/*
857857
* strerror replacement for windows:
858+
*
859+
* We dont't know a fix for win9x yet, but this whould work for nt4 and win2k.
860+
* If you can verify this working on win9x or have a solution, let us know, ok?
861+
*
858862
*/
859863
const char*
860864
winsock_strerror(DWORD eno)
861865
{
862-
if (!FormatMessage(
863-
FORMAT_MESSAGE_IGNORE_INSERTS |
864-
FORMAT_MESSAGE_FROM_SYSTEM | /* always consider system table */
865-
((netmsgModule != NULL) ? FORMAT_MESSAGE_FROM_HMODULE : 0),
866-
netmsgModule, /* module to get message from (NULL == system) */
867-
eno,
868-
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
869-
winsock_strerror_buf,sizeof(winsock_strerror_buf)-1,
870-
NULL
871-
)){
872-
sprintf(winsock_strerror_buf,"Unknown socket error(%u)",eno);
873-
}
874-
winsock_strerror_buf[sizeof(winsock_strerror_buf)-1]='\0';
875-
return winsock_strerror_buf;
866+
#define WSSE_MAXLEN (sizeof(winsock_strerror_buf)-1-12) /* 12 == "(0x00000000)" */
867+
int length;
868+
869+
/* First try the "system table", this works on Win2k pro */
870+
871+
if (FormatMessage(
872+
FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM,
873+
0,eno,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
874+
winsock_strerror_buf,WSSE_MAXLEN,NULL
875+
))
876+
goto WSSE_GOODEXIT;
877+
878+
/* That didn't work, let's try the netmsg.dll */
879+
880+
if (netmsgModule &&
881+
FormatMessage(
882+
FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_HMODULE,
883+
0,eno,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
884+
winsock_strerror_buf,WSSE_MAXLEN,NULL
885+
))
886+
goto WSSE_GOODEXIT;
887+
888+
/* Everything failed, just tell the user that we don't know the desc */
889+
890+
strcat(winsock_strerror_buf,"Socket error, no description available.");
891+
892+
WSSE_GOODEXIT:
893+
894+
length = strlen(winsock_strerror_buf);
895+
sprintf(winsock_strerror_buf + length<WSSE_MAXLEN?length:WSSE_MAXLEN,
896+
"(0x%08X)",eno);
897+
898+
return winsock_strerror_buf;
876899
}
877900
#endif

0 commit comments

Comments
 (0)