]> git.sur5r.net Git - openldap/blob - libraries/liblutil/nt_err.c
Fix broken MSVC builds. The previous round of Mingw32 patches changed some
[openldap] / libraries / liblutil / nt_err.c
1 /* $OpenLDAP$ */
2 #include "portable.h"
3
4 #include <windows.h>
5
6 #ifdef HAVE_WINSOCK2
7 #include <winsock2.h>
8 #elif HAVE_WINSOCK
9 #include <winsock.h>
10 #endif /* HAVE_WINSOCK(2) */
11
12 #define __RETSTR( x ) case x: return #x;
13
14 char *WSAGetErrorString( int err )
15 {
16         switch( err )
17         {
18                 __RETSTR( WSAEINTR )
19                 __RETSTR( WSAEBADF )
20                 __RETSTR( WSAEACCES )
21                 __RETSTR( WSAEFAULT )
22                 __RETSTR( WSAEINVAL )
23                 __RETSTR( WSAEMFILE )
24                 __RETSTR( WSAEWOULDBLOCK )
25                 __RETSTR( WSAEINPROGRESS )
26                 __RETSTR( WSAEALREADY )
27                 __RETSTR( WSAENOTSOCK )
28                 __RETSTR( WSAEDESTADDRREQ )
29                 __RETSTR( WSAEMSGSIZE )
30                 __RETSTR( WSAEPROTOTYPE )
31                 __RETSTR( WSAENOPROTOOPT )
32                 __RETSTR( WSAEPROTONOSUPPORT )
33                 __RETSTR( WSAESOCKTNOSUPPORT )
34                 __RETSTR( WSAEOPNOTSUPP )
35                 __RETSTR( WSAEPFNOSUPPORT )
36                 __RETSTR( WSAEAFNOSUPPORT )
37                 __RETSTR( WSAEADDRINUSE )
38                 __RETSTR( WSAEADDRNOTAVAIL )
39                 __RETSTR( WSAENETDOWN )
40                 __RETSTR( WSAENETUNREACH )
41                 __RETSTR( WSAENETRESET )
42                 __RETSTR( WSAECONNABORTED )
43                 __RETSTR( WSAECONNRESET )
44                 __RETSTR( WSAENOBUFS )
45                 __RETSTR( WSAEISCONN )
46                 __RETSTR( WSAENOTCONN )
47                 __RETSTR( WSAESHUTDOWN )
48                 __RETSTR( WSAETOOMANYREFS )
49                 __RETSTR( WSAETIMEDOUT )
50                 __RETSTR( WSAECONNREFUSED )
51                 __RETSTR( WSAELOOP )
52                 __RETSTR( WSAENAMETOOLONG )
53                 __RETSTR( WSAEHOSTDOWN )
54                 __RETSTR( WSAEHOSTUNREACH )
55                 __RETSTR( WSAENOTEMPTY )
56                 __RETSTR( WSAEPROCLIM )
57                 __RETSTR( WSAEUSERS )
58                 __RETSTR( WSAEDQUOT )
59                 __RETSTR( WSAESTALE )
60                 __RETSTR( WSAEREMOTE )
61                 __RETSTR( WSASYSNOTREADY )
62                 __RETSTR( WSAVERNOTSUPPORTED )
63                 __RETSTR( WSANOTINITIALISED )
64                 __RETSTR( WSAEDISCON )
65
66 #ifdef HAVE_WINSOCK2
67                 __RETSTR( WSAENOMORE )
68                 __RETSTR( WSAECANCELLED )
69                 __RETSTR( WSAEINVALIDPROCTABLE )
70                 __RETSTR( WSAEINVALIDPROVIDER )
71                 __RETSTR( WSASYSCALLFAILURE )
72                 __RETSTR( WSASERVICE_NOT_FOUND )
73                 __RETSTR( WSATYPE_NOT_FOUND )
74                 __RETSTR( WSA_E_NO_MORE )
75                 __RETSTR( WSA_E_CANCELLED )
76                 __RETSTR( WSAEREFUSED )
77 #endif // HAVE_WINSOCK2 
78
79                 __RETSTR( WSAHOST_NOT_FOUND )
80                 __RETSTR( WSATRY_AGAIN )
81                 __RETSTR( WSANO_RECOVERY )
82                 __RETSTR( WSANO_DATA )
83         }
84         return "unknown";
85 }
86
87 char *WSAGetLastErrorString( void )
88 {
89         return WSAGetErrorString( WSAGetLastError() );
90 }
91
92 #undef __RETSTR
93
94 char *GetErrorString( int err )
95 {
96         static char msgBuf[1024];
97
98         FormatMessage(
99                 FORMAT_MESSAGE_FROM_SYSTEM,
100                 NULL,
101                 err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
102                 msgBuf, 1024, NULL );
103
104         return msgBuf;
105 }
106
107 char *GetLastErrorString( void )
108 {
109         return GetErrorString( GetLastError() );
110 }
111
112
113