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 * ***** BEGIN LICENSE BLOCK *****
11 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
13 * The contents of this file are subject to the Mozilla Public License Version
14 * 1.1 (the "License"); you may not use this file except in compliance with
15 * the License. You may obtain a copy of the License at
16 * http://www.mozilla.org/MPL/
18 * Software distributed under the License is distributed on an "AS IS" basis,
19 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
20 * for the specific language governing rights and limitations under the
23 * The Original Code is the Netscape security libraries.
25 * The Initial Developer of the Original Code is
26 * Netscape Communications Corporation.
27 * Portions created by the Initial Developer are Copyright (C) 1994-2000
28 * the Initial Developer. All Rights Reserved.
32 * Alternatively, the contents of this file may be used under the terms of
33 * either the GNU General Public License Version 2 or later (the "GPL"), or
34 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
35 * in which case the provisions of the GPL or the LGPL are applicable instead
36 * of those above. If you wish to allow use of your version of this file only
37 * under the terms of either the GPL or the LGPL, and not to allow others to
38 * use your version of this file under the terms of the MPL, indicate your
39 * decision by deleting the provisions above and replace them with the notice
40 * and other provisions required by the GPL or the LGPL. If you do not delete
41 * the provisions above, a recipient may use your version of this file under
42 * the terms of any one of the MPL, the GPL or the LGPL.
44 * ***** END LICENSE BLOCK ***** */
45 /* $Id: win32err.c,v 1.4 2004/04/27 23:04:39 gerv%gerv.net Exp $ */
47 #if !defined(_WIN32_WCE)
55 * On Win32, we map three kinds of error codes:
56 * - GetLastError(): for Win32 functions
57 * - WSAGetLastError(): for Winsock functions
58 * - errno: for standard C library functions
60 * We do not check for WSAEINPROGRESS and WSAEINTR because we do not
61 * use blocking Winsock 1.1 calls.
63 * Except for the 'socket' call, we do not check for WSAEINITIALISED.
64 * It is assumed that if Winsock is not initialized, that fact will
65 * be detected at the time we create new sockets.
68 /* forward declaration. */
69 void nss_MD_win32_map_default_error(PRInt32 err
);
71 void nss_MD_win32_map_opendir_error(PRInt32 err
)
73 nss_MD_win32_map_default_error(err
);
76 void nss_MD_win32_map_closedir_error(PRInt32 err
)
78 nss_MD_win32_map_default_error(err
);
81 void nss_MD_win32_map_readdir_error(PRInt32 err
)
83 nss_MD_win32_map_default_error(err
);
86 void nss_MD_win32_map_delete_error(PRInt32 err
)
88 nss_MD_win32_map_default_error(err
);
91 /* The error code for stat() is in errno. */
92 void nss_MD_win32_map_stat_error(PRInt32 err
)
94 nss_MD_win32_map_default_error(err
);
97 void nss_MD_win32_map_fstat_error(PRInt32 err
)
99 nss_MD_win32_map_default_error(err
);
102 void nss_MD_win32_map_rename_error(PRInt32 err
)
104 nss_MD_win32_map_default_error(err
);
107 /* The error code for access() is in errno. */
108 void nss_MD_win32_map_access_error(PRInt32 err
)
110 nss_MD_win32_map_default_error(err
);
113 void nss_MD_win32_map_mkdir_error(PRInt32 err
)
115 nss_MD_win32_map_default_error(err
);
118 void nss_MD_win32_map_rmdir_error(PRInt32 err
)
120 nss_MD_win32_map_default_error(err
);
123 void nss_MD_win32_map_read_error(PRInt32 err
)
125 nss_MD_win32_map_default_error(err
);
128 void nss_MD_win32_map_transmitfile_error(PRInt32 err
)
130 nss_MD_win32_map_default_error(err
);
133 void nss_MD_win32_map_write_error(PRInt32 err
)
135 nss_MD_win32_map_default_error(err
);
138 void nss_MD_win32_map_lseek_error(PRInt32 err
)
140 nss_MD_win32_map_default_error(err
);
143 void nss_MD_win32_map_fsync_error(PRInt32 err
)
145 nss_MD_win32_map_default_error(err
);
149 * For both CloseHandle() and closesocket().
151 void nss_MD_win32_map_close_error(PRInt32 err
)
153 nss_MD_win32_map_default_error(err
);
156 void nss_MD_win32_map_socket_error(PRInt32 err
)
158 PR_ASSERT(err
!= WSANOTINITIALISED
);
159 nss_MD_win32_map_default_error(err
);
162 void nss_MD_win32_map_recv_error(PRInt32 err
)
164 nss_MD_win32_map_default_error(err
);
167 void nss_MD_win32_map_recvfrom_error(PRInt32 err
)
169 nss_MD_win32_map_default_error(err
);
172 void nss_MD_win32_map_send_error(PRInt32 err
)
176 case WSAEMSGSIZE
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
177 default: nss_MD_win32_map_default_error(err
); return;
179 PR_SetError(prError
, err
);
182 void nss_MD_win32_map_sendto_error(PRInt32 err
)
186 case WSAEMSGSIZE
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
187 default: nss_MD_win32_map_default_error(err
); return;
189 PR_SetError(prError
, err
);
192 void nss_MD_win32_map_accept_error(PRInt32 err
)
196 case WSAEOPNOTSUPP
: prError
= PR_NOT_TCP_SOCKET_ERROR
; break;
197 case WSAEINVAL
: prError
= PR_INVALID_STATE_ERROR
; break;
198 default: nss_MD_win32_map_default_error(err
); return;
200 PR_SetError(prError
, err
);
203 void nss_MD_win32_map_acceptex_error(PRInt32 err
)
205 nss_MD_win32_map_default_error(err
);
208 void nss_MD_win32_map_connect_error(PRInt32 err
)
212 case WSAEWOULDBLOCK
: prError
= PR_IN_PROGRESS_ERROR
; break;
213 case WSAEINVAL
: prError
= PR_ALREADY_INITIATED_ERROR
; break;
214 case WSAETIMEDOUT
: prError
= PR_IO_TIMEOUT_ERROR
; break;
215 default: nss_MD_win32_map_default_error(err
); return;
217 PR_SetError(prError
, err
);
220 void nss_MD_win32_map_bind_error(PRInt32 err
)
224 case WSAEINVAL
: prError
= PR_SOCKET_ADDRESS_IS_BOUND_ERROR
; break;
225 default: nss_MD_win32_map_default_error(err
); return;
227 PR_SetError(prError
, err
);
230 void nss_MD_win32_map_listen_error(PRInt32 err
)
234 case WSAEOPNOTSUPP
: prError
= PR_NOT_TCP_SOCKET_ERROR
; break;
235 case WSAEINVAL
: prError
= PR_INVALID_STATE_ERROR
; break;
236 default: nss_MD_win32_map_default_error(err
); return;
238 PR_SetError(prError
, err
);
241 void nss_MD_win32_map_shutdown_error(PRInt32 err
)
243 nss_MD_win32_map_default_error(err
);
246 void nss_MD_win32_map_getsockname_error(PRInt32 err
)
250 case WSAEINVAL
: prError
= PR_INVALID_STATE_ERROR
; break;
251 default: nss_MD_win32_map_default_error(err
); return;
253 PR_SetError(prError
, err
);
256 void nss_MD_win32_map_getpeername_error(PRInt32 err
)
258 nss_MD_win32_map_default_error(err
);
261 void nss_MD_win32_map_getsockopt_error(PRInt32 err
)
263 nss_MD_win32_map_default_error(err
);
266 void nss_MD_win32_map_setsockopt_error(PRInt32 err
)
268 nss_MD_win32_map_default_error(err
);
271 void nss_MD_win32_map_open_error(PRInt32 err
)
273 nss_MD_win32_map_default_error(err
);
276 void nss_MD_win32_map_gethostname_error(PRInt32 err
)
278 nss_MD_win32_map_default_error(err
);
281 /* Win32 select() only works on sockets. So in this
282 ** context, WSAENOTSOCK is equivalent to EBADF on Unix.
284 void nss_MD_win32_map_select_error(PRInt32 err
)
288 case WSAENOTSOCK
: prError
= PR_BAD_DESCRIPTOR_ERROR
; break;
289 default: nss_MD_win32_map_default_error(err
); return;
291 PR_SetError(prError
, err
);
294 void nss_MD_win32_map_lockf_error(PRInt32 err
)
296 nss_MD_win32_map_default_error(err
);
301 void nss_MD_win32_map_default_error(PRInt32 err
)
306 case EACCES
: prError
= PR_NO_ACCESS_RIGHTS_ERROR
; break;
307 case ENOENT
: prError
= PR_FILE_NOT_FOUND_ERROR
; break;
308 case ERROR_ACCESS_DENIED
: prError
= PR_NO_ACCESS_RIGHTS_ERROR
; break;
309 case ERROR_ALREADY_EXISTS
: prError
= PR_FILE_EXISTS_ERROR
; break;
310 case ERROR_DISK_CORRUPT
: prError
= PR_IO_ERROR
; break;
311 case ERROR_DISK_FULL
: prError
= PR_NO_DEVICE_SPACE_ERROR
; break;
312 case ERROR_DISK_OPERATION_FAILED
: prError
= PR_IO_ERROR
; break;
313 case ERROR_DRIVE_LOCKED
: prError
= PR_FILE_IS_LOCKED_ERROR
; break;
314 case ERROR_FILENAME_EXCED_RANGE
: prError
= PR_NAME_TOO_LONG_ERROR
; break;
315 case ERROR_FILE_CORRUPT
: prError
= PR_IO_ERROR
; break;
316 case ERROR_FILE_EXISTS
: prError
= PR_FILE_EXISTS_ERROR
; break;
317 case ERROR_FILE_INVALID
: prError
= PR_BAD_DESCRIPTOR_ERROR
; break;
318 #if ERROR_FILE_NOT_FOUND != ENOENT
319 case ERROR_FILE_NOT_FOUND
: prError
= PR_FILE_NOT_FOUND_ERROR
; break;
321 case ERROR_HANDLE_DISK_FULL
: prError
= PR_NO_DEVICE_SPACE_ERROR
; break;
322 case ERROR_INVALID_ADDRESS
: prError
= PR_ACCESS_FAULT_ERROR
; break;
323 case ERROR_INVALID_HANDLE
: prError
= PR_BAD_DESCRIPTOR_ERROR
; break;
324 case ERROR_INVALID_NAME
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
325 case ERROR_INVALID_PARAMETER
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
326 case ERROR_INVALID_USER_BUFFER
: prError
= PR_INSUFFICIENT_RESOURCES_ERROR
; break;
327 case ERROR_LOCKED
: prError
= PR_FILE_IS_LOCKED_ERROR
; break;
328 case ERROR_NETNAME_DELETED
: prError
= PR_CONNECT_RESET_ERROR
; break;
329 case ERROR_NOACCESS
: prError
= PR_ACCESS_FAULT_ERROR
; break;
330 case ERROR_NOT_ENOUGH_MEMORY
: prError
= PR_INSUFFICIENT_RESOURCES_ERROR
; break;
331 case ERROR_NOT_ENOUGH_QUOTA
: prError
= PR_OUT_OF_MEMORY_ERROR
; break;
332 case ERROR_NOT_READY
: prError
= PR_IO_ERROR
; break;
333 case ERROR_NO_MORE_FILES
: prError
= PR_NO_MORE_FILES_ERROR
; break;
334 case ERROR_OPEN_FAILED
: prError
= PR_IO_ERROR
; break;
335 case ERROR_OPEN_FILES
: prError
= PR_IO_ERROR
; break;
336 case ERROR_OUTOFMEMORY
: prError
= PR_INSUFFICIENT_RESOURCES_ERROR
; break;
337 case ERROR_PATH_BUSY
: prError
= PR_IO_ERROR
; break;
338 case ERROR_PATH_NOT_FOUND
: prError
= PR_FILE_NOT_FOUND_ERROR
; break;
339 case ERROR_SEEK_ON_DEVICE
: prError
= PR_IO_ERROR
; break;
340 case ERROR_SHARING_VIOLATION
: prError
= PR_FILE_IS_BUSY_ERROR
; break;
341 case ERROR_STACK_OVERFLOW
: prError
= PR_ACCESS_FAULT_ERROR
; break;
342 case ERROR_TOO_MANY_OPEN_FILES
: prError
= PR_SYS_DESC_TABLE_FULL_ERROR
; break;
343 case ERROR_WRITE_PROTECT
: prError
= PR_NO_ACCESS_RIGHTS_ERROR
; break;
344 case WSAEACCES
: prError
= PR_NO_ACCESS_RIGHTS_ERROR
; break;
345 case WSAEADDRINUSE
: prError
= PR_ADDRESS_IN_USE_ERROR
; break;
346 case WSAEADDRNOTAVAIL
: prError
= PR_ADDRESS_NOT_AVAILABLE_ERROR
; break;
347 case WSAEAFNOSUPPORT
: prError
= PR_ADDRESS_NOT_SUPPORTED_ERROR
; break;
348 case WSAEALREADY
: prError
= PR_ALREADY_INITIATED_ERROR
; break;
349 case WSAEBADF
: prError
= PR_BAD_DESCRIPTOR_ERROR
; break;
350 case WSAECONNABORTED
: prError
= PR_CONNECT_ABORTED_ERROR
; break;
351 case WSAECONNREFUSED
: prError
= PR_CONNECT_REFUSED_ERROR
; break;
352 case WSAECONNRESET
: prError
= PR_CONNECT_RESET_ERROR
; break;
353 case WSAEDESTADDRREQ
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
354 case WSAEFAULT
: prError
= PR_ACCESS_FAULT_ERROR
; break;
355 case WSAEHOSTUNREACH
: prError
= PR_HOST_UNREACHABLE_ERROR
; break;
356 case WSAEINVAL
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
357 case WSAEISCONN
: prError
= PR_IS_CONNECTED_ERROR
; break;
358 case WSAEMFILE
: prError
= PR_PROC_DESC_TABLE_FULL_ERROR
; break;
359 case WSAEMSGSIZE
: prError
= PR_BUFFER_OVERFLOW_ERROR
; break;
360 case WSAENETDOWN
: prError
= PR_NETWORK_DOWN_ERROR
; break;
361 case WSAENETRESET
: prError
= PR_CONNECT_ABORTED_ERROR
; break;
362 case WSAENETUNREACH
: prError
= PR_NETWORK_UNREACHABLE_ERROR
; break;
363 case WSAENOBUFS
: prError
= PR_INSUFFICIENT_RESOURCES_ERROR
; break;
364 case WSAENOPROTOOPT
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
365 case WSAENOTCONN
: prError
= PR_NOT_CONNECTED_ERROR
; break;
366 case WSAENOTSOCK
: prError
= PR_NOT_SOCKET_ERROR
; break;
367 case WSAEOPNOTSUPP
: prError
= PR_OPERATION_NOT_SUPPORTED_ERROR
; break;
368 case WSAEPROTONOSUPPORT
: prError
= PR_PROTOCOL_NOT_SUPPORTED_ERROR
; break;
369 case WSAEPROTOTYPE
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
370 case WSAESHUTDOWN
: prError
= PR_SOCKET_SHUTDOWN_ERROR
; break;
371 case WSAESOCKTNOSUPPORT
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
372 case WSAETIMEDOUT
: prError
= PR_CONNECT_ABORTED_ERROR
; break;
373 case WSAEWOULDBLOCK
: prError
= PR_WOULD_BLOCK_ERROR
; break;
374 default: prError
= PR_UNKNOWN_ERROR
; break;
376 PR_SetError(prError
, err
);