1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 * This file essentially replicates NSPR's source for the functions that
4 * map system-specific error codes to NSPR error codes. We would use
5 * NSPR's functions, instead of duplicating them, but they're private.
6 * As long as SSL's server session cache code must do platform native I/O
7 * to accomplish its job, and NSPR's error mapping functions remain private,
8 * this code will continue to need to be replicated.
10 * This Source Code Form is subject to the terms of the Mozilla Public
11 * License, v. 2.0. If a copy of the MPL was not distributed with this
12 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
13 /* $Id: win32err.c,v 1.6 2012/04/25 14:50:12 gerv%gerv.net Exp $ */
21 * On Win32, we map three kinds of error codes:
22 * - GetLastError(): for Win32 functions
23 * - WSAGetLastError(): for Winsock functions
24 * - errno: for standard C library functions
26 * We do not check for WSAEINPROGRESS and WSAEINTR because we do not
27 * use blocking Winsock 1.1 calls.
29 * Except for the 'socket' call, we do not check for WSAEINITIALISED.
30 * It is assumed that if Winsock is not initialized, that fact will
31 * be detected at the time we create new sockets.
34 /* forward declaration. */
35 void nss_MD_win32_map_default_error(PRInt32 err
);
37 void nss_MD_win32_map_opendir_error(PRInt32 err
)
39 nss_MD_win32_map_default_error(err
);
42 void nss_MD_win32_map_closedir_error(PRInt32 err
)
44 nss_MD_win32_map_default_error(err
);
47 void nss_MD_win32_map_readdir_error(PRInt32 err
)
49 nss_MD_win32_map_default_error(err
);
52 void nss_MD_win32_map_delete_error(PRInt32 err
)
54 nss_MD_win32_map_default_error(err
);
57 /* The error code for stat() is in errno. */
58 void nss_MD_win32_map_stat_error(PRInt32 err
)
60 nss_MD_win32_map_default_error(err
);
63 void nss_MD_win32_map_fstat_error(PRInt32 err
)
65 nss_MD_win32_map_default_error(err
);
68 void nss_MD_win32_map_rename_error(PRInt32 err
)
70 nss_MD_win32_map_default_error(err
);
73 /* The error code for access() is in errno. */
74 void nss_MD_win32_map_access_error(PRInt32 err
)
76 nss_MD_win32_map_default_error(err
);
79 void nss_MD_win32_map_mkdir_error(PRInt32 err
)
81 nss_MD_win32_map_default_error(err
);
84 void nss_MD_win32_map_rmdir_error(PRInt32 err
)
86 nss_MD_win32_map_default_error(err
);
89 void nss_MD_win32_map_read_error(PRInt32 err
)
91 nss_MD_win32_map_default_error(err
);
94 void nss_MD_win32_map_transmitfile_error(PRInt32 err
)
96 nss_MD_win32_map_default_error(err
);
99 void nss_MD_win32_map_write_error(PRInt32 err
)
101 nss_MD_win32_map_default_error(err
);
104 void nss_MD_win32_map_lseek_error(PRInt32 err
)
106 nss_MD_win32_map_default_error(err
);
109 void nss_MD_win32_map_fsync_error(PRInt32 err
)
111 nss_MD_win32_map_default_error(err
);
115 * For both CloseHandle() and closesocket().
117 void nss_MD_win32_map_close_error(PRInt32 err
)
119 nss_MD_win32_map_default_error(err
);
122 void nss_MD_win32_map_socket_error(PRInt32 err
)
124 PR_ASSERT(err
!= WSANOTINITIALISED
);
125 nss_MD_win32_map_default_error(err
);
128 void nss_MD_win32_map_recv_error(PRInt32 err
)
130 nss_MD_win32_map_default_error(err
);
133 void nss_MD_win32_map_recvfrom_error(PRInt32 err
)
135 nss_MD_win32_map_default_error(err
);
138 void nss_MD_win32_map_send_error(PRInt32 err
)
142 case WSAEMSGSIZE
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
143 default: nss_MD_win32_map_default_error(err
); return;
145 PR_SetError(prError
, err
);
148 void nss_MD_win32_map_sendto_error(PRInt32 err
)
152 case WSAEMSGSIZE
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
153 default: nss_MD_win32_map_default_error(err
); return;
155 PR_SetError(prError
, err
);
158 void nss_MD_win32_map_accept_error(PRInt32 err
)
162 case WSAEOPNOTSUPP
: prError
= PR_NOT_TCP_SOCKET_ERROR
; break;
163 case WSAEINVAL
: prError
= PR_INVALID_STATE_ERROR
; break;
164 default: nss_MD_win32_map_default_error(err
); return;
166 PR_SetError(prError
, err
);
169 void nss_MD_win32_map_acceptex_error(PRInt32 err
)
171 nss_MD_win32_map_default_error(err
);
174 void nss_MD_win32_map_connect_error(PRInt32 err
)
178 case WSAEWOULDBLOCK
: prError
= PR_IN_PROGRESS_ERROR
; break;
179 case WSAEINVAL
: prError
= PR_ALREADY_INITIATED_ERROR
; break;
180 case WSAETIMEDOUT
: prError
= PR_IO_TIMEOUT_ERROR
; break;
181 default: nss_MD_win32_map_default_error(err
); return;
183 PR_SetError(prError
, err
);
186 void nss_MD_win32_map_bind_error(PRInt32 err
)
190 case WSAEINVAL
: prError
= PR_SOCKET_ADDRESS_IS_BOUND_ERROR
; break;
191 default: nss_MD_win32_map_default_error(err
); return;
193 PR_SetError(prError
, err
);
196 void nss_MD_win32_map_listen_error(PRInt32 err
)
200 case WSAEOPNOTSUPP
: prError
= PR_NOT_TCP_SOCKET_ERROR
; break;
201 case WSAEINVAL
: prError
= PR_INVALID_STATE_ERROR
; break;
202 default: nss_MD_win32_map_default_error(err
); return;
204 PR_SetError(prError
, err
);
207 void nss_MD_win32_map_shutdown_error(PRInt32 err
)
209 nss_MD_win32_map_default_error(err
);
212 void nss_MD_win32_map_getsockname_error(PRInt32 err
)
216 case WSAEINVAL
: prError
= PR_INVALID_STATE_ERROR
; break;
217 default: nss_MD_win32_map_default_error(err
); return;
219 PR_SetError(prError
, err
);
222 void nss_MD_win32_map_getpeername_error(PRInt32 err
)
224 nss_MD_win32_map_default_error(err
);
227 void nss_MD_win32_map_getsockopt_error(PRInt32 err
)
229 nss_MD_win32_map_default_error(err
);
232 void nss_MD_win32_map_setsockopt_error(PRInt32 err
)
234 nss_MD_win32_map_default_error(err
);
237 void nss_MD_win32_map_open_error(PRInt32 err
)
239 nss_MD_win32_map_default_error(err
);
242 void nss_MD_win32_map_gethostname_error(PRInt32 err
)
244 nss_MD_win32_map_default_error(err
);
247 /* Win32 select() only works on sockets. So in this
248 ** context, WSAENOTSOCK is equivalent to EBADF on Unix.
250 void nss_MD_win32_map_select_error(PRInt32 err
)
254 case WSAENOTSOCK
: prError
= PR_BAD_DESCRIPTOR_ERROR
; break;
255 default: nss_MD_win32_map_default_error(err
); return;
257 PR_SetError(prError
, err
);
260 void nss_MD_win32_map_lockf_error(PRInt32 err
)
262 nss_MD_win32_map_default_error(err
);
267 void nss_MD_win32_map_default_error(PRInt32 err
)
272 case EACCES
: prError
= PR_NO_ACCESS_RIGHTS_ERROR
; break;
273 case ENOENT
: prError
= PR_FILE_NOT_FOUND_ERROR
; break;
274 case ERROR_ACCESS_DENIED
: prError
= PR_NO_ACCESS_RIGHTS_ERROR
; break;
275 case ERROR_ALREADY_EXISTS
: prError
= PR_FILE_EXISTS_ERROR
; break;
276 case ERROR_DISK_CORRUPT
: prError
= PR_IO_ERROR
; break;
277 case ERROR_DISK_FULL
: prError
= PR_NO_DEVICE_SPACE_ERROR
; break;
278 case ERROR_DISK_OPERATION_FAILED
: prError
= PR_IO_ERROR
; break;
279 case ERROR_DRIVE_LOCKED
: prError
= PR_FILE_IS_LOCKED_ERROR
; break;
280 case ERROR_FILENAME_EXCED_RANGE
: prError
= PR_NAME_TOO_LONG_ERROR
; break;
281 case ERROR_FILE_CORRUPT
: prError
= PR_IO_ERROR
; break;
282 case ERROR_FILE_EXISTS
: prError
= PR_FILE_EXISTS_ERROR
; break;
283 case ERROR_FILE_INVALID
: prError
= PR_BAD_DESCRIPTOR_ERROR
; break;
284 #if ERROR_FILE_NOT_FOUND != ENOENT
285 case ERROR_FILE_NOT_FOUND
: prError
= PR_FILE_NOT_FOUND_ERROR
; break;
287 case ERROR_HANDLE_DISK_FULL
: prError
= PR_NO_DEVICE_SPACE_ERROR
; break;
288 case ERROR_INVALID_ADDRESS
: prError
= PR_ACCESS_FAULT_ERROR
; break;
289 case ERROR_INVALID_HANDLE
: prError
= PR_BAD_DESCRIPTOR_ERROR
; break;
290 case ERROR_INVALID_NAME
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
291 case ERROR_INVALID_PARAMETER
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
292 case ERROR_INVALID_USER_BUFFER
: prError
= PR_INSUFFICIENT_RESOURCES_ERROR
; break;
293 case ERROR_LOCKED
: prError
= PR_FILE_IS_LOCKED_ERROR
; break;
294 case ERROR_NETNAME_DELETED
: prError
= PR_CONNECT_RESET_ERROR
; break;
295 case ERROR_NOACCESS
: prError
= PR_ACCESS_FAULT_ERROR
; break;
296 case ERROR_NOT_ENOUGH_MEMORY
: prError
= PR_INSUFFICIENT_RESOURCES_ERROR
; break;
297 case ERROR_NOT_ENOUGH_QUOTA
: prError
= PR_OUT_OF_MEMORY_ERROR
; break;
298 case ERROR_NOT_READY
: prError
= PR_IO_ERROR
; break;
299 case ERROR_NO_MORE_FILES
: prError
= PR_NO_MORE_FILES_ERROR
; break;
300 case ERROR_OPEN_FAILED
: prError
= PR_IO_ERROR
; break;
301 case ERROR_OPEN_FILES
: prError
= PR_IO_ERROR
; break;
302 case ERROR_OUTOFMEMORY
: prError
= PR_INSUFFICIENT_RESOURCES_ERROR
; break;
303 case ERROR_PATH_BUSY
: prError
= PR_IO_ERROR
; break;
304 case ERROR_PATH_NOT_FOUND
: prError
= PR_FILE_NOT_FOUND_ERROR
; break;
305 case ERROR_SEEK_ON_DEVICE
: prError
= PR_IO_ERROR
; break;
306 case ERROR_SHARING_VIOLATION
: prError
= PR_FILE_IS_BUSY_ERROR
; break;
307 case ERROR_STACK_OVERFLOW
: prError
= PR_ACCESS_FAULT_ERROR
; break;
308 case ERROR_TOO_MANY_OPEN_FILES
: prError
= PR_SYS_DESC_TABLE_FULL_ERROR
; break;
309 case ERROR_WRITE_PROTECT
: prError
= PR_NO_ACCESS_RIGHTS_ERROR
; break;
310 case WSAEACCES
: prError
= PR_NO_ACCESS_RIGHTS_ERROR
; break;
311 case WSAEADDRINUSE
: prError
= PR_ADDRESS_IN_USE_ERROR
; break;
312 case WSAEADDRNOTAVAIL
: prError
= PR_ADDRESS_NOT_AVAILABLE_ERROR
; break;
313 case WSAEAFNOSUPPORT
: prError
= PR_ADDRESS_NOT_SUPPORTED_ERROR
; break;
314 case WSAEALREADY
: prError
= PR_ALREADY_INITIATED_ERROR
; break;
315 case WSAEBADF
: prError
= PR_BAD_DESCRIPTOR_ERROR
; break;
316 case WSAECONNABORTED
: prError
= PR_CONNECT_ABORTED_ERROR
; break;
317 case WSAECONNREFUSED
: prError
= PR_CONNECT_REFUSED_ERROR
; break;
318 case WSAECONNRESET
: prError
= PR_CONNECT_RESET_ERROR
; break;
319 case WSAEDESTADDRREQ
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
320 case WSAEFAULT
: prError
= PR_ACCESS_FAULT_ERROR
; break;
321 case WSAEHOSTUNREACH
: prError
= PR_HOST_UNREACHABLE_ERROR
; break;
322 case WSAEINVAL
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
323 case WSAEISCONN
: prError
= PR_IS_CONNECTED_ERROR
; break;
324 case WSAEMFILE
: prError
= PR_PROC_DESC_TABLE_FULL_ERROR
; break;
325 case WSAEMSGSIZE
: prError
= PR_BUFFER_OVERFLOW_ERROR
; break;
326 case WSAENETDOWN
: prError
= PR_NETWORK_DOWN_ERROR
; break;
327 case WSAENETRESET
: prError
= PR_CONNECT_ABORTED_ERROR
; break;
328 case WSAENETUNREACH
: prError
= PR_NETWORK_UNREACHABLE_ERROR
; break;
329 case WSAENOBUFS
: prError
= PR_INSUFFICIENT_RESOURCES_ERROR
; break;
330 case WSAENOPROTOOPT
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
331 case WSAENOTCONN
: prError
= PR_NOT_CONNECTED_ERROR
; break;
332 case WSAENOTSOCK
: prError
= PR_NOT_SOCKET_ERROR
; break;
333 case WSAEOPNOTSUPP
: prError
= PR_OPERATION_NOT_SUPPORTED_ERROR
; break;
334 case WSAEPROTONOSUPPORT
: prError
= PR_PROTOCOL_NOT_SUPPORTED_ERROR
; break;
335 case WSAEPROTOTYPE
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
336 case WSAESHUTDOWN
: prError
= PR_SOCKET_SHUTDOWN_ERROR
; break;
337 case WSAESOCKTNOSUPPORT
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
338 case WSAETIMEDOUT
: prError
= PR_CONNECT_ABORTED_ERROR
; break;
339 case WSAEWOULDBLOCK
: prError
= PR_WOULD_BLOCK_ERROR
; break;
340 default: prError
= PR_UNKNOWN_ERROR
; break;
342 PR_SetError(prError
, err
);