8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libldap5 / sources / ldap / prldap / ldappr-error.c
blob83f41bb54ca70bbbfd179f966cf59ff969324203
1 #pragma ident "%Z%%M% %I% %E% SMI"
3 /*
4 * The contents of this file are subject to the Netscape Public
5 * License Version 1.1 (the "License"); you may not use this file
6 * except in compliance with the License. You may obtain a copy of
7 * the License at http://www.mozilla.org/NPL/
9 * Software distributed under the License is distributed on an "AS
10 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 * implied. See the License for the specific language governing
12 * rights and limitations under the License.
14 * The Original Code is Mozilla Communicator client code, released
15 * March 31, 1998.
17 * The Initial Developer of the Original Code is Netscape
18 * Communications Corporation. Portions created by Netscape are
19 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
20 * Rights Reserved.
22 * Contributor(s):
26 * Utilities for manageing the relationship between NSPR errors and
27 * OS (errno-style) errors.
29 * The overall strategy used is to map NSPR errors into OS errors.
32 #include "ldappr-int.h"
35 void
36 prldap_set_system_errno( int oserrno )
38 PR_SetError( PR_UNKNOWN_ERROR, oserrno );
42 int
43 prldap_get_system_errno( void )
45 return( PR_GetOSError());
49 * Retrieve the NSPR error number, convert to a system error code, and return
50 * the result.
52 struct prldap_errormap_entry {
53 PRInt32 erm_nspr; /* NSPR error code */
54 int erm_system; /* corresponding system error code */
57 /* XXX: not sure if this extra mapping for Windows is good or correct */
58 #ifdef _WINDOWS
59 #ifndef ENOTSUP
60 #define ENOTSUP -1
61 #endif
62 #ifndef ETIMEDOUT
63 #define ETIMEDOUT WSAETIMEDOUT
64 #endif
65 #ifndef EADDRNOTAVAIL
66 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
67 #endif
68 #ifndef EAFNOSUPPORT
69 #define EAFNOSUPPORT WSAEAFNOSUPPORT
70 #endif
71 #ifndef EISCONN
72 #define EISCONN WSAEISCONN
73 #endif
74 #ifndef EADDRINUSE
75 #define EADDRINUSE WSAEADDRINUSE
76 #endif
77 #ifndef ECONNREFUSED
78 #define ECONNREFUSED WSAECONNREFUSED
79 #endif
80 #ifndef EHOSTUNREACH
81 #define EHOSTUNREACH WSAEHOSTUNREACH
82 #endif
83 #ifndef ENOTCONN
84 #define ENOTCONN WSAENOTCONN
85 #endif
86 #ifndef ENOTSOCK
87 #define ENOTSOCK WSAENOTSOCK
88 #endif
89 #ifndef EPROTOTYPE
90 #define EPROTOTYPE WSAEPROTOTYPE
91 #endif
92 #ifndef EOPNOTSUPP
93 #define EOPNOTSUPP WSAEOPNOTSUPP
94 #endif
95 #ifndef EPROTONOSUPPORT
96 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
97 #endif
98 #ifndef EOVERFLOW
99 #define EOVERFLOW -1
100 #endif
101 #ifndef ECONNRESET
102 #define ECONNRESET WSAECONNRESET
103 #endif
104 #ifndef ELOOP
105 #define ELOOP WSAELOOP
106 #endif
107 #ifndef ENOTBLK
108 #define ENOTBLK -1
109 #endif
110 #ifndef ETXTBSY
111 #define ETXTBSY -1
112 #endif
113 #ifndef ENETDOWN
114 #define ENETDOWN WSAENETDOWN
115 #endif
116 #ifndef ESHUTDOWN
117 #define ESHUTDOWN WSAESHUTDOWN
118 #endif
119 #ifndef ECONNABORTED
120 #define ECONNABORTED WSAECONNABORTED
121 #endif
122 #endif /* _WINDOWS */
124 /* XXX: need to verify that the -1 entries are correct (no mapping) */
125 static struct prldap_errormap_entry prldap_errormap[] = {
126 { PR_OUT_OF_MEMORY_ERROR, ENOMEM },
127 { PR_BAD_DESCRIPTOR_ERROR, EBADF },
128 { PR_WOULD_BLOCK_ERROR, EAGAIN },
129 { PR_ACCESS_FAULT_ERROR, EFAULT },
130 { PR_INVALID_METHOD_ERROR, EINVAL }, /* XXX: correct mapping ? */
131 { PR_ILLEGAL_ACCESS_ERROR, EACCES }, /* XXX: correct mapping ? */
132 { PR_UNKNOWN_ERROR, -1 },
133 { PR_PENDING_INTERRUPT_ERROR, -1 },
134 { PR_NOT_IMPLEMENTED_ERROR, ENOTSUP },
135 { PR_IO_ERROR, EIO },
136 { PR_IO_TIMEOUT_ERROR, ETIMEDOUT }, /* XXX: correct mapping ? */
137 { PR_IO_PENDING_ERROR, -1 },
138 { PR_DIRECTORY_OPEN_ERROR, ENOTDIR },
139 { PR_INVALID_ARGUMENT_ERROR, EINVAL },
140 { PR_ADDRESS_NOT_AVAILABLE_ERROR, EADDRNOTAVAIL },
141 { PR_ADDRESS_NOT_SUPPORTED_ERROR, EAFNOSUPPORT },
142 { PR_IS_CONNECTED_ERROR, EISCONN },
143 { PR_BAD_ADDRESS_ERROR, EFAULT }, /* XXX: correct mapping ? */
144 { PR_ADDRESS_IN_USE_ERROR, EADDRINUSE },
145 { PR_CONNECT_REFUSED_ERROR, ECONNREFUSED },
146 { PR_NETWORK_UNREACHABLE_ERROR, EHOSTUNREACH },
147 { PR_CONNECT_TIMEOUT_ERROR, ETIMEDOUT },
148 { PR_NOT_CONNECTED_ERROR, ENOTCONN },
149 { PR_LOAD_LIBRARY_ERROR, -1 },
150 { PR_UNLOAD_LIBRARY_ERROR, -1 },
151 { PR_FIND_SYMBOL_ERROR, -1 },
152 { PR_INSUFFICIENT_RESOURCES_ERROR, -1 },
153 { PR_DIRECTORY_LOOKUP_ERROR, -1 },
154 { PR_TPD_RANGE_ERROR, -1 },
155 { PR_PROC_DESC_TABLE_FULL_ERROR, -1 },
156 { PR_SYS_DESC_TABLE_FULL_ERROR, -1 },
157 { PR_NOT_SOCKET_ERROR, ENOTSOCK },
158 { PR_NOT_TCP_SOCKET_ERROR, EPROTOTYPE },
159 { PR_SOCKET_ADDRESS_IS_BOUND_ERROR, -1 },
160 { PR_NO_ACCESS_RIGHTS_ERROR, EACCES }, /* XXX: correct mapping ? */
161 { PR_OPERATION_NOT_SUPPORTED_ERROR, EOPNOTSUPP },
162 { PR_PROTOCOL_NOT_SUPPORTED_ERROR, EPROTONOSUPPORT },
163 { PR_REMOTE_FILE_ERROR, -1 },
164 #if defined(OSF1)
165 { PR_BUFFER_OVERFLOW_ERROR, -1 },
166 #else
167 { PR_BUFFER_OVERFLOW_ERROR, EOVERFLOW },
168 #endif /* OSF1 */
169 { PR_CONNECT_RESET_ERROR, ECONNRESET },
170 { PR_RANGE_ERROR, ERANGE },
171 { PR_DEADLOCK_ERROR, EDEADLK },
172 #if defined(HPUX11) || defined(AIX4_3) || defined(OSF1)
173 { PR_FILE_IS_LOCKED_ERROR, -1 }, /* XXX: correct mapping ? */
174 #else
175 { PR_FILE_IS_LOCKED_ERROR, EDEADLOCK }, /* XXX: correct mapping ? */
176 #endif /* HPUX11 */
177 { PR_FILE_TOO_BIG_ERROR, EFBIG },
178 { PR_NO_DEVICE_SPACE_ERROR, ENOSPC },
179 { PR_PIPE_ERROR, EPIPE },
180 { PR_NO_SEEK_DEVICE_ERROR, ESPIPE },
181 { PR_IS_DIRECTORY_ERROR, EISDIR },
182 { PR_LOOP_ERROR, ELOOP },
183 { PR_NAME_TOO_LONG_ERROR, ENAMETOOLONG },
184 { PR_FILE_NOT_FOUND_ERROR, ENOENT },
185 { PR_NOT_DIRECTORY_ERROR, ENOTDIR },
186 { PR_READ_ONLY_FILESYSTEM_ERROR, EROFS },
187 { PR_DIRECTORY_NOT_EMPTY_ERROR, ENOTEMPTY },
188 { PR_FILESYSTEM_MOUNTED_ERROR, EBUSY },
189 { PR_NOT_SAME_DEVICE_ERROR, EXDEV },
190 { PR_DIRECTORY_CORRUPTED_ERROR, -1 },
191 { PR_FILE_EXISTS_ERROR, EEXIST },
192 { PR_MAX_DIRECTORY_ENTRIES_ERROR, -1 },
193 { PR_INVALID_DEVICE_STATE_ERROR, ENOTBLK }, /* XXX: correct mapping ? */
194 { PR_DEVICE_IS_LOCKED_ERROR, -2 },
195 { PR_NO_MORE_FILES_ERROR, ENFILE },
196 { PR_END_OF_FILE_ERROR, -1 },
197 { PR_FILE_SEEK_ERROR, ESPIPE }, /* XXX: correct mapping ? */
198 { PR_FILE_IS_BUSY_ERROR, ETXTBSY },
199 { PR_OPERATION_ABORTED_ERROR, -1 },
200 { PR_IN_PROGRESS_ERROR, -1 },
201 { PR_ALREADY_INITIATED_ERROR, -1 },
202 { PR_GROUP_EMPTY_ERROR, -1 },
203 { PR_INVALID_STATE_ERROR, -1 },
204 { PR_NETWORK_DOWN_ERROR, ENETDOWN },
205 { PR_SOCKET_SHUTDOWN_ERROR, ESHUTDOWN },
206 { PR_CONNECT_ABORTED_ERROR, ECONNABORTED },
207 { PR_HOST_UNREACHABLE_ERROR, EHOSTUNREACH },
208 { PR_MAX_ERROR, -1 },
213 prldap_prerr2errno( void )
215 int oserr, i;
216 PRInt32 nsprerr;
218 nsprerr = PR_GetError();
220 oserr = -1; /* unknown */
221 for ( i = 0; prldap_errormap[i].erm_nspr != PR_MAX_ERROR; ++i ) {
222 if ( prldap_errormap[i].erm_nspr == nsprerr ) {
223 oserr = prldap_errormap[i].erm_system;
224 break;
228 return( oserr );