1 #pragma ident "%Z%%M% %I% %E% SMI"
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
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
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"
36 prldap_set_system_errno( int oserrno
)
38 PR_SetError( PR_UNKNOWN_ERROR
, oserrno
);
43 prldap_get_system_errno( void )
45 return( PR_GetOSError());
49 * Retrieve the NSPR error number, convert to a system error code, and return
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 */
63 #define ETIMEDOUT WSAETIMEDOUT
66 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
69 #define EAFNOSUPPORT WSAEAFNOSUPPORT
72 #define EISCONN WSAEISCONN
75 #define EADDRINUSE WSAEADDRINUSE
78 #define ECONNREFUSED WSAECONNREFUSED
81 #define EHOSTUNREACH WSAEHOSTUNREACH
84 #define ENOTCONN WSAENOTCONN
87 #define ENOTSOCK WSAENOTSOCK
90 #define EPROTOTYPE WSAEPROTOTYPE
93 #define EOPNOTSUPP WSAEOPNOTSUPP
95 #ifndef EPROTONOSUPPORT
96 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
102 #define ECONNRESET WSAECONNRESET
105 #define ELOOP WSAELOOP
114 #define ENETDOWN WSAENETDOWN
117 #define ESHUTDOWN WSAESHUTDOWN
120 #define ECONNABORTED WSAECONNABORTED
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 },
165 { PR_BUFFER_OVERFLOW_ERROR
, -1 },
167 { PR_BUFFER_OVERFLOW_ERROR
, EOVERFLOW
},
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 ? */
175 { PR_FILE_IS_LOCKED_ERROR
, EDEADLOCK
}, /* XXX: correct mapping ? */
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 )
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
;