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