Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit30571b5

Browse files
committed
I'm at the win32 error messages once more. The DLL load thingy doesn't
work on all win9x machines, so i made it go thru a l ookup tableinstead, using the DLL as last resort. I also moved this out of thefe-misc.c file because of the size of the lookup ta ble. Who knows, wemight add more other win32 specific code there in the future.I also fixed a small typo in the pg_config.h.win32 that made thecompiler compla in about the gnu snprintf declaration.I tried to make this patch with psql coding style. I've successfullytested this on win2k and win98 and it works fine (i.e. the mes sageshows on win98 too, it didn't with the old implementation).Magnus Naeslund
1 parentdd4ca82 commit30571b5

File tree

4 files changed

+188
-50
lines changed

4 files changed

+188
-50
lines changed

‎src/include/pg_config.h.win32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define HAVE_NAMESPACE_STD
2929

3030
/* use _snprintf instead of snprintf */
31-
#defineHAVE_SNPRINTF_DECL
31+
#defineHAVE_DECL_SNPRINTF 1
3232
#define snprintf_snprintf
3333

3434
/* defines for dynamic linking on Win32 platform */

‎src/interfaces/libpq/fe-misc.c

Lines changed: 1 addition & 46 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.69 2002/04/15 23:34:17 momjian Exp $
28+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.70 2002/04/24 02:26:06 momjian Exp $
2929
*
3030
*-------------------------------------------------------------------------
3131
*/
@@ -37,8 +37,6 @@
3737
#include<time.h>
3838

3939
#ifdefWIN32
40-
#defineWIN32_LEAN_AND_MEAN
41-
#include<windows.h>
4240
#include"win32.h"
4341
#else
4442
#include<unistd.h>
@@ -894,46 +892,3 @@ libpq_gettext(const char *msgid)
894892
returndgettext("libpq",msgid);
895893
}
896894
#endif/* ENABLE_NLS */
897-
898-
#ifdefWIN32
899-
/*
900-
* strerror replacement for windows:
901-
*
902-
* This works on WIN2000 and newer, but we don't know where to find WinSock
903-
* error strings on older Windows flavors. If you know, clue us in.
904-
*/
905-
constchar*
906-
winsock_strerror(inteno)
907-
{
908-
staticcharerr_buf[512];
909-
#defineWSSE_MAXLEN (sizeof(err_buf)-1-13)/* 13 for " (0x00000000)" */
910-
intlength;
911-
912-
/* First try the "system table", this works on Win2k and up */
913-
914-
if (FormatMessage(
915-
FORMAT_MESSAGE_IGNORE_INSERTS |FORMAT_MESSAGE_FROM_SYSTEM,
916-
0,
917-
eno,
918-
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
919-
err_buf,
920-
WSSE_MAXLEN,
921-
NULL))
922-
gotoWSSE_GOODEXIT;
923-
924-
/* Insert other possible lookup methods here ... */
925-
926-
/* Everything failed, just tell the user that we don't know the desc */
927-
928-
strcpy(err_buf,"Socket error, no description available.");
929-
930-
WSSE_GOODEXIT:
931-
932-
length=strlen(err_buf);
933-
sprintf(err_buf+ (length<WSSE_MAXLEN ?length :WSSE_MAXLEN),
934-
" (0x%08X)",eno);
935-
936-
returnerr_buf;
937-
}
938-
939-
#endif

‎src/interfaces/libpq/win32.c

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*
2+
*FILE
3+
*win32.c
4+
*
5+
*DESCRIPTION
6+
*Win32 support functions.
7+
*
8+
* Contains table and functions for looking up win32 socket error
9+
* descriptions. But will/may contain other win32 helper functions
10+
* for libpq.
11+
*
12+
* The error constants are taken from the Frambak Bakfram LGSOCKET
13+
* library guys who in turn took them from the Winsock FAQ.
14+
*
15+
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
16+
* Portions Copyright (c) 1994, Regents of the University of California
17+
*
18+
*/
19+
20+
#defineWIN32_LEAN_AND_MEAN
21+
#include<windows.h>
22+
#include<winsock.h>
23+
#include<stdio.h>
24+
#include"win32.h"
25+
26+
staticstructWSErrorEntry {
27+
DWORDerror;
28+
constchar*description;
29+
}WSErrors []= {
30+
{0,"No error"},
31+
{WSAEINTR,"Interrupted system call"},
32+
{WSAEBADF,"Bad file number"},
33+
{WSAEACCES,"Permission denied"},
34+
{WSAEFAULT,"Bad address"},
35+
{WSAEINVAL,"Invalid argument"},
36+
{WSAEMFILE,"Too many open sockets"},
37+
{WSAEWOULDBLOCK,"Operation would block"},
38+
{WSAEINPROGRESS,"Operation now in progress"},
39+
{WSAEALREADY,"Operation already in progress"},
40+
{WSAENOTSOCK,"Socket operation on non-socket"},
41+
{WSAEDESTADDRREQ,"Destination address required"},
42+
{WSAEMSGSIZE,"Message too long"},
43+
{WSAEPROTOTYPE,"Protocol wrong type for socket"},
44+
{WSAENOPROTOOPT,"Bad protocol option"},
45+
{WSAEPROTONOSUPPORT,"Protocol not supported"},
46+
{WSAESOCKTNOSUPPORT,"Socket type not supported"},
47+
{WSAEOPNOTSUPP,"Operation not supported on socket"},
48+
{WSAEPFNOSUPPORT,"Protocol family not supported"},
49+
{WSAEAFNOSUPPORT,"Address family not supported"},
50+
{WSAEADDRINUSE,"Address already in use"},
51+
{WSAEADDRNOTAVAIL,"Can't assign requested address"},
52+
{WSAENETDOWN,"Network is down"},
53+
{WSAENETUNREACH,"Network is unreachable"},
54+
{WSAENETRESET,"Net connection reset"},
55+
{WSAECONNABORTED,"Software caused connection abort"},
56+
{WSAECONNRESET,"Connection reset by peer"},
57+
{WSAENOBUFS,"No buffer space available"},
58+
{WSAEISCONN,"Socket is already connected"},
59+
{WSAENOTCONN,"Socket is not connected"},
60+
{WSAESHUTDOWN,"Can't send after socket shutdown"},
61+
{WSAETOOMANYREFS,"Too many references, can't splice"},
62+
{WSAETIMEDOUT,"Connection timed out"},
63+
{WSAECONNREFUSED,"Connection refused"},
64+
{WSAELOOP,"Too many levels of symbolic links"},
65+
{WSAENAMETOOLONG,"File name too long"},
66+
{WSAEHOSTDOWN,"Host is down"},
67+
{WSAEHOSTUNREACH,"No route to host"},
68+
{WSAENOTEMPTY,"Directory not empty"},
69+
{WSAEPROCLIM,"Too many processes"},
70+
{WSAEUSERS,"Too many users"},
71+
{WSAEDQUOT,"Disc quota exceeded"},
72+
{WSAESTALE,"Stale NFS file handle"},
73+
{WSAEREMOTE,"Too many levels of remote in path"},
74+
{WSASYSNOTREADY,"Network system is unavailable"},
75+
{WSAVERNOTSUPPORTED,"Winsock version out of range"},
76+
{WSANOTINITIALISED,"WSAStartup not yet called"},
77+
{WSAEDISCON,"Graceful shutdown in progress"},
78+
{WSAHOST_NOT_FOUND,"Host not found"},
79+
{WSATRY_AGAIN,"NA Host not found / SERVFAIL"},
80+
{WSANO_RECOVERY,"Non recoverable FORMERR||REFUSED||NOTIMP"},
81+
{WSANO_DATA,"No host data of that type was found"},
82+
{0,0}/* End of table */
83+
};
84+
85+
86+
/*
87+
* Returns 0 if not found, linear but who cares, at this moment
88+
* we're already in pain :)
89+
*/
90+
91+
staticintLookupWSErrorMessage(DWORDerr,char*dest)
92+
{
93+
structWSErrorEntry*e;
94+
for (e=WSErrors;e->description;e++)
95+
{
96+
if (e->error==err)
97+
{
98+
strcpy(dest,e->description);
99+
return1;
100+
}
101+
}
102+
return0;
103+
}
104+
105+
106+
structMessageDLL{
107+
constchar*dll_name;
108+
void*handle;
109+
intloaded;/* BOOL */
110+
}dlls[]={
111+
{"netmsg.dll",0,0},
112+
{"winsock.dll",0,0},
113+
{"wsock32.dll",0,0},
114+
{"ws2_32.dll",0,0},
115+
{"wsock32n.dll",0,0},
116+
{"mswsock.dll",0,0},
117+
{"ws2help.dll",0,0},
118+
{"ws2thk.dll",0,0},
119+
{0,0,1}/* Last one, no dll, always loaded */
120+
};
121+
122+
#defineDLLS_SIZE (sizeof(dlls)/sizeof(struct MessageDLL))
123+
124+
/*
125+
* Returns a description of the socket error by first trying
126+
* to find it in the lookup table, and if that fails, tries
127+
* to load any of the winsock dlls to find that message.
128+
* The DLL thing works from Nt4 (spX ?) up, but some special
129+
* versions of winsock might have this aswell (seen on Win98 SE
130+
* special install) / Magnus Naeslund (mag@fbab.net)
131+
*
132+
*/
133+
134+
constchar*winsock_strerror(interr){
135+
staticcharbuf[512];/* Not threadsafe */
136+
unsigned longflags;
137+
intoffs,i;
138+
intsuccess=LookupWSErrorMessage(err,buf);
139+
140+
for (i=0;!success&&i<DLLS_SIZE;i++)
141+
{
142+
143+
if (!dlls[i].loaded)
144+
{
145+
dlls[i].loaded=1;/* Only load once */
146+
dlls[i].handle= (void*)LoadLibraryEx(
147+
dlls[i].dll_name,
148+
0,
149+
LOAD_LIBRARY_AS_DATAFILE);
150+
}
151+
152+
if (dlls[i].dll_name&& !dlls[i].handle)
153+
continue;/* Didn't load */
154+
155+
flags=FORMAT_MESSAGE_FROM_SYSTEM
156+
|FORMAT_MESSAGE_IGNORE_INSERTS
157+
| (dlls[i].handle?FORMAT_MESSAGE_FROM_HMODULE:0);
158+
159+
success=0!=FormatMessage(
160+
flags,
161+
dlls[i].handle,err,
162+
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
163+
buf,sizeof(buf)-64,
164+
0
165+
);
166+
}
167+
168+
if (!success)
169+
{
170+
sprintf(buf,"Unknown socket error (0x%08X/%lu)",err,err);
171+
}
172+
else
173+
{
174+
buf[sizeof(buf)-1]='\0';
175+
offs=strlen(buf);
176+
if (offs>sizeof(buf)-64)
177+
offs=sizeof(buf)-64;
178+
sprintf(buf+offs," (0x%08X/%lu)",err,err);
179+
}
180+
returnbuf;
181+
}
182+

‎src/interfaces/libpq/win32.mak

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ CLEAN :
6464
-@erase"$(INTDIR)\fe-print.obj"
6565
-@erase"$(INTDIR)\pqexpbuffer.obj"
6666
-@erase"$(OUTDIR)\libpqdll.obj"
67+
-@erase"$(OUTDIR)\win32.obj"
6768
-@erase"$(OUTDIR)\libpq.lib"
6869
-@erase"$(OUTDIR)\libpq.dll"
6970
-@erase"$(OUTDIR)\libpq.res"
@@ -96,6 +97,7 @@ CPP_SBRS=.
9697
LIB32=link.exe -lib
9798
LIB32_FLAGS=/nologo /out:"$(OUTDIR)\libpq.lib"
9899
LIB32_OBJS=\
100+
"$(OUTDIR)\win32.obj"\
99101
"$(INTDIR)\dllist.obj"\
100102
"$(INTDIR)\md5.obj"\
101103
"$(INTDIR)\fe-auth.obj"\
@@ -113,9 +115,8 @@ LIB32_OBJS = $(LIB32_OBJS) "$(INTDIR)\wchar.obj" "$(INTDIR)\encnames.obj"
113115
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\libpq.res"
114116

115117
LINK32=link.exe
116-
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
117-
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib wsock32.lib\
118-
odbccp32.lib /nologo /subsystem:windows /dll /incremental:no\
118+
LINK32_FLAGS=kernel32.lib user32.lib advapi32.lib wsock32.lib\
119+
/nologo /subsystem:windows /dll /incremental:no\
119120
/pdb:"$(OUTDIR)\libpqdll.pdb" /machine:I386 /out:"$(OUTDIR)\libpq.dll"\
120121
/implib:"$(OUTDIR)\libpqdll.lib" /def:libpqdll.def
121122
LINK32_OBJS=\

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp