]> git.sur5r.net Git - openldap/blob - libraries/liblutil/nt_err.c
Use new macros from configure.in to accomodate NT/Mingw32 environment.
[openldap] / libraries / liblutil / nt_err.c
1 /* $OpenLDAP$ */
2 #include "portable.h"
3
4 #include <windows.h>
5
6 #ifdef HAVE_WINSOCK
7 #include <winsock.h>
8
9 #define __RETSTR( x ) case x: return #x;
10
11 char *WSAGetErrorString( int err )
12 {
13         switch( err )
14         {
15                 __RETSTR( WSAEINTR )
16                 __RETSTR( WSAEBADF )
17                 __RETSTR( WSAEACCES )
18                 __RETSTR( WSAEFAULT )
19                 __RETSTR( WSAEINVAL )
20                 __RETSTR( WSAEMFILE )
21                 __RETSTR( WSAEWOULDBLOCK )
22                 __RETSTR( WSAEINPROGRESS )
23                 __RETSTR( WSAEALREADY )
24                 __RETSTR( WSAENOTSOCK )
25                 __RETSTR( WSAEDESTADDRREQ )
26                 __RETSTR( WSAEMSGSIZE )
27                 __RETSTR( WSAEPROTOTYPE )
28                 __RETSTR( WSAENOPROTOOPT )
29                 __RETSTR( WSAEPROTONOSUPPORT )
30                 __RETSTR( WSAESOCKTNOSUPPORT )
31                 __RETSTR( WSAEOPNOTSUPP )
32                 __RETSTR( WSAEPFNOSUPPORT )
33                 __RETSTR( WSAEAFNOSUPPORT )
34                 __RETSTR( WSAEADDRINUSE )
35                 __RETSTR( WSAEADDRNOTAVAIL )
36                 __RETSTR( WSAENETDOWN )
37                 __RETSTR( WSAENETUNREACH )
38                 __RETSTR( WSAENETRESET )
39                 __RETSTR( WSAECONNABORTED )
40                 __RETSTR( WSAECONNRESET )
41                 __RETSTR( WSAENOBUFS )
42                 __RETSTR( WSAEISCONN )
43                 __RETSTR( WSAENOTCONN )
44                 __RETSTR( WSAESHUTDOWN )
45                 __RETSTR( WSAETOOMANYREFS )
46                 __RETSTR( WSAETIMEDOUT )
47                 __RETSTR( WSAECONNREFUSED )
48                 __RETSTR( WSAELOOP )
49                 __RETSTR( WSAENAMETOOLONG )
50                 __RETSTR( WSAEHOSTDOWN )
51                 __RETSTR( WSAEHOSTUNREACH )
52                 __RETSTR( WSAENOTEMPTY )
53                 __RETSTR( WSAEPROCLIM )
54                 __RETSTR( WSAEUSERS )
55                 __RETSTR( WSAEDQUOT )
56                 __RETSTR( WSAESTALE )
57                 __RETSTR( WSAEREMOTE )
58                 __RETSTR( WSASYSNOTREADY )
59                 __RETSTR( WSAVERNOTSUPPORTED )
60                 __RETSTR( WSANOTINITIALISED )
61                 __RETSTR( WSAEDISCON )
62
63 #ifdef HAVE_WINSOCK2
64                 __RETSTR( WSAENOMORE )
65                 __RETSTR( WSAECANCELLED )
66                 __RETSTR( WSAEINVALIDPROCTABLE )
67                 __RETSTR( WSAEINVALIDPROVIDER )
68                 __RETSTR( WSASYSCALLFAILURE )
69                 __RETSTR( WSASERVICE_NOT_FOUND )
70                 __RETSTR( WSATYPE_NOT_FOUND )
71                 __RETSTR( WSA_E_NO_MORE )
72                 __RETSTR( WSA_E_CANCELLED )
73                 __RETSTR( WSAEREFUSED )
74 #endif // HAVE_WINSOCK2 
75
76                 __RETSTR( WSAHOST_NOT_FOUND )
77                 __RETSTR( WSATRY_AGAIN )
78                 __RETSTR( WSANO_RECOVERY )
79                 __RETSTR( WSANO_DATA )
80         }
81         return "unknown";
82 }
83
84 char *WSAGetLastErrorString( void )
85 {
86         return WSAGetErrorString( WSAGetLastError() );
87 }
88
89 #undef __RETSTR
90
91 #endif /* HAVE_WINSOCK */
92
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