Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / net / third_party / nss / ssl / unix_err.c
blobeb3d00062938a9bb12cf85eeaed1d1bc37df455f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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.
9 *
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: unix_err.c,v 1.9 2012/04/25 14:50:12 gerv%gerv.net Exp $ */
15 #if 0
16 #include "primpl.h"
17 #else
18 #define _PR_POLL_AVAILABLE 1
19 #include "prerror.h"
20 #endif
22 #if defined (__bsdi__) || defined(NTO) || defined(DARWIN) || defined(BEOS)
23 #undef _PR_POLL_AVAILABLE
24 #endif
26 #if defined(_PR_POLL_AVAILABLE)
27 #include <poll.h>
28 #endif
29 #include <errno.h>
31 /* forward declarations. */
32 void nss_MD_unix_map_default_error(int err);
34 void nss_MD_unix_map_opendir_error(int err)
36 nss_MD_unix_map_default_error(err);
39 void nss_MD_unix_map_closedir_error(int err)
41 PRErrorCode prError;
42 switch (err) {
43 case EINVAL: prError = PR_BAD_DESCRIPTOR_ERROR; break;
44 default: nss_MD_unix_map_default_error(err); return;
46 PR_SetError(prError, err);
49 void nss_MD_unix_readdir_error(int err)
51 PRErrorCode prError;
53 switch (err) {
54 case ENOENT: prError = PR_NO_MORE_FILES_ERROR; break;
55 #ifdef EOVERFLOW
56 case EOVERFLOW: prError = PR_IO_ERROR; break;
57 #endif
58 case EINVAL: prError = PR_IO_ERROR; break;
59 case ENXIO: prError = PR_IO_ERROR; break;
60 default: nss_MD_unix_map_default_error(err); return;
62 PR_SetError(prError, err);
65 void nss_MD_unix_map_unlink_error(int err)
67 PRErrorCode prError;
68 switch (err) {
69 case EPERM: prError = PR_IS_DIRECTORY_ERROR; break;
70 default: nss_MD_unix_map_default_error(err); return;
72 PR_SetError(prError, err);
75 void nss_MD_unix_map_stat_error(int err)
77 PRErrorCode prError;
78 switch (err) {
79 case ETIMEDOUT: prError = PR_REMOTE_FILE_ERROR; break;
80 default: nss_MD_unix_map_default_error(err); return;
82 PR_SetError(prError, err);
85 void nss_MD_unix_map_fstat_error(int err)
87 PRErrorCode prError;
88 switch (err) {
89 case ETIMEDOUT: prError = PR_REMOTE_FILE_ERROR; break;
90 default: nss_MD_unix_map_default_error(err); return;
92 PR_SetError(prError, err);
95 void nss_MD_unix_map_rename_error(int err)
97 PRErrorCode prError;
98 switch (err) {
99 case EEXIST: prError = PR_DIRECTORY_NOT_EMPTY_ERROR; break;
100 default: nss_MD_unix_map_default_error(err); return;
102 PR_SetError(prError, err);
105 void nss_MD_unix_map_access_error(int err)
107 PRErrorCode prError;
108 switch (err) {
109 case ETIMEDOUT: prError = PR_REMOTE_FILE_ERROR; break;
110 default: nss_MD_unix_map_default_error(err); return;
112 PR_SetError(prError, err);
115 void nss_MD_unix_map_mkdir_error(int err)
117 nss_MD_unix_map_default_error(err);
120 void nss_MD_unix_map_rmdir_error(int err)
122 PRErrorCode prError;
124 switch (err) {
125 case EEXIST: prError = PR_DIRECTORY_NOT_EMPTY_ERROR; break;
126 case EINVAL: prError = PR_DIRECTORY_NOT_EMPTY_ERROR; break;
127 case ETIMEDOUT: prError = PR_REMOTE_FILE_ERROR; break;
128 default: nss_MD_unix_map_default_error(err); return;
130 PR_SetError(prError, err);
133 void nss_MD_unix_map_read_error(int err)
135 PRErrorCode prError;
136 switch (err) {
137 case EINVAL: prError = PR_INVALID_METHOD_ERROR; break;
138 case ENXIO: prError = PR_INVALID_ARGUMENT_ERROR; break;
139 default: nss_MD_unix_map_default_error(err); return;
141 PR_SetError(prError, err);
144 void nss_MD_unix_map_write_error(int err)
146 PRErrorCode prError;
147 switch (err) {
148 case EINVAL: prError = PR_INVALID_METHOD_ERROR; break;
149 case ENXIO: prError = PR_INVALID_METHOD_ERROR; break;
150 case ETIMEDOUT: prError = PR_REMOTE_FILE_ERROR; break;
151 default: nss_MD_unix_map_default_error(err); return;
153 PR_SetError(prError, err);
156 void nss_MD_unix_map_lseek_error(int err)
158 nss_MD_unix_map_default_error(err);
161 void nss_MD_unix_map_fsync_error(int err)
163 PRErrorCode prError;
164 switch (err) {
165 case ETIMEDOUT: prError = PR_REMOTE_FILE_ERROR; break;
166 case EINVAL: prError = PR_INVALID_METHOD_ERROR; break;
167 default: nss_MD_unix_map_default_error(err); return;
169 PR_SetError(prError, err);
172 void nss_MD_unix_map_close_error(int err)
174 PRErrorCode prError;
175 switch (err) {
176 case ETIMEDOUT: prError = PR_REMOTE_FILE_ERROR; break;
177 default: nss_MD_unix_map_default_error(err); return;
179 PR_SetError(prError, err);
182 void nss_MD_unix_map_socket_error(int err)
184 PRErrorCode prError;
185 switch (err) {
186 case ENOMEM: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
187 default: nss_MD_unix_map_default_error(err); return;
189 PR_SetError(prError, err);
192 void nss_MD_unix_map_socketavailable_error(int err)
194 PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
197 void nss_MD_unix_map_recv_error(int err)
199 nss_MD_unix_map_default_error(err);
202 void nss_MD_unix_map_recvfrom_error(int err)
204 nss_MD_unix_map_default_error(err);
207 void nss_MD_unix_map_send_error(int err)
209 nss_MD_unix_map_default_error(err);
212 void nss_MD_unix_map_sendto_error(int err)
214 nss_MD_unix_map_default_error(err);
217 void nss_MD_unix_map_writev_error(int err)
219 nss_MD_unix_map_default_error(err);
222 void nss_MD_unix_map_accept_error(int err)
224 PRErrorCode prError;
225 switch (err) {
226 case ENODEV: prError = PR_NOT_TCP_SOCKET_ERROR; break;
227 default: nss_MD_unix_map_default_error(err); return;
229 PR_SetError(prError, err);
232 void nss_MD_unix_map_connect_error(int err)
234 PRErrorCode prError;
235 switch (err) {
236 case EACCES: prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break;
237 #if defined(UNIXWARE) || defined(SNI) || defined(NEC)
239 * On some platforms, if we connect to a port on the local host
240 * (the loopback address) that no process is listening on, we get
241 * EIO instead of ECONNREFUSED.
243 case EIO: prError = PR_CONNECT_REFUSED_ERROR; break;
244 #endif
245 case ELOOP: prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break;
246 case ENOENT: prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break;
247 case ENXIO: prError = PR_IO_ERROR; break;
248 default: nss_MD_unix_map_default_error(err); return;
250 PR_SetError(prError, err);
253 void nss_MD_unix_map_bind_error(int err)
255 PRErrorCode prError;
256 switch (err) {
257 case EINVAL: prError = PR_SOCKET_ADDRESS_IS_BOUND_ERROR; break;
259 * UNIX domain sockets are not supported in NSPR
261 case EIO: prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break;
262 case EISDIR: prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break;
263 case ELOOP: prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break;
264 case ENOENT: prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break;
265 case ENOTDIR: prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break;
266 case EROFS: prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break;
267 default: nss_MD_unix_map_default_error(err); return;
269 PR_SetError(prError, err);
272 void nss_MD_unix_map_listen_error(int err)
274 nss_MD_unix_map_default_error(err);
277 void nss_MD_unix_map_shutdown_error(int err)
279 nss_MD_unix_map_default_error(err);
282 void nss_MD_unix_map_socketpair_error(int err)
284 PRErrorCode prError;
285 switch (err) {
286 case ENOMEM: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
287 default: nss_MD_unix_map_default_error(err); return;
289 PR_SetError(prError, err);
292 void nss_MD_unix_map_getsockname_error(int err)
294 PRErrorCode prError;
295 switch (err) {
296 case ENOMEM: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
297 default: nss_MD_unix_map_default_error(err); return;
299 PR_SetError(prError, err);
302 void nss_MD_unix_map_getpeername_error(int err)
304 PRErrorCode prError;
306 switch (err) {
307 case ENOMEM: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
308 default: nss_MD_unix_map_default_error(err); return;
310 PR_SetError(prError, err);
313 void nss_MD_unix_map_getsockopt_error(int err)
315 PRErrorCode prError;
316 switch (err) {
317 case EINVAL: prError = PR_BUFFER_OVERFLOW_ERROR; break;
318 case ENOMEM: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
319 default: nss_MD_unix_map_default_error(err); return;
321 PR_SetError(prError, err);
324 void nss_MD_unix_map_setsockopt_error(int err)
326 PRErrorCode prError;
327 switch (err) {
328 case EINVAL: prError = PR_BUFFER_OVERFLOW_ERROR; break;
329 case ENOMEM: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
330 default: nss_MD_unix_map_default_error(err); return;
332 PR_SetError(prError, err);
335 void nss_MD_unix_map_open_error(int err)
337 PRErrorCode prError;
338 switch (err) {
339 case EAGAIN: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
340 case EBUSY: prError = PR_IO_ERROR; break;
341 case ENODEV: prError = PR_FILE_NOT_FOUND_ERROR; break;
342 case ENOMEM: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
343 case ETIMEDOUT: prError = PR_REMOTE_FILE_ERROR; break;
344 default: nss_MD_unix_map_default_error(err); return;
346 PR_SetError(prError, err);
349 void nss_MD_unix_map_mmap_error(int err)
351 PRErrorCode prError;
352 switch (err) {
353 case EAGAIN: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
354 case EMFILE: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
355 case ENODEV: prError = PR_OPERATION_NOT_SUPPORTED_ERROR; break;
356 case ENXIO: prError = PR_INVALID_ARGUMENT_ERROR; break;
357 default: nss_MD_unix_map_default_error(err); return;
359 PR_SetError(prError, err);
362 void nss_MD_unix_map_gethostname_error(int err)
364 nss_MD_unix_map_default_error(err);
367 void nss_MD_unix_map_select_error(int err)
369 nss_MD_unix_map_default_error(err);
372 #ifdef _PR_POLL_AVAILABLE
373 void nss_MD_unix_map_poll_error(int err)
375 PRErrorCode prError;
377 switch (err) {
378 case EAGAIN: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
379 default: nss_MD_unix_map_default_error(err); return;
381 PR_SetError(prError, err);
384 void nss_MD_unix_map_poll_revents_error(int err)
386 if (err & POLLNVAL)
387 PR_SetError(PR_BAD_DESCRIPTOR_ERROR, EBADF);
388 else if (err & POLLHUP)
389 PR_SetError(PR_CONNECT_RESET_ERROR, EPIPE);
390 else if (err & POLLERR)
391 PR_SetError(PR_IO_ERROR, EIO);
392 else
393 PR_SetError(PR_UNKNOWN_ERROR, err);
395 #endif /* _PR_POLL_AVAILABLE */
398 void nss_MD_unix_map_flock_error(int err)
400 PRErrorCode prError;
401 switch (err) {
402 case EINVAL: prError = PR_BAD_DESCRIPTOR_ERROR; break;
403 case EWOULDBLOCK: prError = PR_FILE_IS_LOCKED_ERROR; break;
404 default: nss_MD_unix_map_default_error(err); return;
406 PR_SetError(prError, err);
409 void nss_MD_unix_map_lockf_error(int err)
411 PRErrorCode prError;
412 switch (err) {
413 case EACCES: prError = PR_FILE_IS_LOCKED_ERROR; break;
414 case EDEADLK: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
415 default: nss_MD_unix_map_default_error(err); return;
417 PR_SetError(prError, err);
420 #ifdef HPUX11
421 void nss_MD_hpux_map_sendfile_error(int err)
423 nss_MD_unix_map_default_error(err);
425 #endif /* HPUX11 */
428 void nss_MD_unix_map_default_error(int err)
430 PRErrorCode prError;
431 switch (err ) {
432 case EACCES: prError = PR_NO_ACCESS_RIGHTS_ERROR; break;
433 case EADDRINUSE: prError = PR_ADDRESS_IN_USE_ERROR; break;
434 case EADDRNOTAVAIL: prError = PR_ADDRESS_NOT_AVAILABLE_ERROR; break;
435 case EAFNOSUPPORT: prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break;
436 case EAGAIN: prError = PR_WOULD_BLOCK_ERROR; break;
438 * On QNX and Neutrino, EALREADY is defined as EBUSY.
440 #if EALREADY != EBUSY
441 case EALREADY: prError = PR_ALREADY_INITIATED_ERROR; break;
442 #endif
443 case EBADF: prError = PR_BAD_DESCRIPTOR_ERROR; break;
444 #ifdef EBADMSG
445 case EBADMSG: prError = PR_IO_ERROR; break;
446 #endif
447 case EBUSY: prError = PR_FILESYSTEM_MOUNTED_ERROR; break;
448 case ECONNREFUSED: prError = PR_CONNECT_REFUSED_ERROR; break;
449 case ECONNRESET: prError = PR_CONNECT_RESET_ERROR; break;
450 case EDEADLK: prError = PR_DEADLOCK_ERROR; break;
451 #ifdef EDIRCORRUPTED
452 case EDIRCORRUPTED: prError = PR_DIRECTORY_CORRUPTED_ERROR; break;
453 #endif
454 #ifdef EDQUOT
455 case EDQUOT: prError = PR_NO_DEVICE_SPACE_ERROR; break;
456 #endif
457 case EEXIST: prError = PR_FILE_EXISTS_ERROR; break;
458 case EFAULT: prError = PR_ACCESS_FAULT_ERROR; break;
459 case EFBIG: prError = PR_FILE_TOO_BIG_ERROR; break;
460 case EINPROGRESS: prError = PR_IN_PROGRESS_ERROR; break;
461 case EINTR: prError = PR_PENDING_INTERRUPT_ERROR; break;
462 case EINVAL: prError = PR_INVALID_ARGUMENT_ERROR; break;
463 case EIO: prError = PR_IO_ERROR; break;
464 case EISCONN: prError = PR_IS_CONNECTED_ERROR; break;
465 case EISDIR: prError = PR_IS_DIRECTORY_ERROR; break;
466 case ELOOP: prError = PR_LOOP_ERROR; break;
467 case EMFILE: prError = PR_PROC_DESC_TABLE_FULL_ERROR; break;
468 case EMLINK: prError = PR_MAX_DIRECTORY_ENTRIES_ERROR; break;
469 case EMSGSIZE: prError = PR_INVALID_ARGUMENT_ERROR; break;
470 #ifdef EMULTIHOP
471 case EMULTIHOP: prError = PR_REMOTE_FILE_ERROR; break;
472 #endif
473 case ENAMETOOLONG: prError = PR_NAME_TOO_LONG_ERROR; break;
474 case ENETUNREACH: prError = PR_NETWORK_UNREACHABLE_ERROR; break;
475 case ENFILE: prError = PR_SYS_DESC_TABLE_FULL_ERROR; break;
476 #if !defined(SCO)
477 case ENOBUFS: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
478 #endif
479 case ENODEV: prError = PR_FILE_NOT_FOUND_ERROR; break;
480 case ENOENT: prError = PR_FILE_NOT_FOUND_ERROR; break;
481 case ENOLCK: prError = PR_FILE_IS_LOCKED_ERROR; break;
482 #ifdef ENOLINK
483 case ENOLINK: prError = PR_REMOTE_FILE_ERROR; break;
484 #endif
485 case ENOMEM: prError = PR_OUT_OF_MEMORY_ERROR; break;
486 case ENOPROTOOPT: prError = PR_INVALID_ARGUMENT_ERROR; break;
487 case ENOSPC: prError = PR_NO_DEVICE_SPACE_ERROR; break;
488 #ifdef ENOSR
489 case ENOSR: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
490 #endif
491 case ENOTCONN: prError = PR_NOT_CONNECTED_ERROR; break;
492 case ENOTDIR: prError = PR_NOT_DIRECTORY_ERROR; break;
493 case ENOTSOCK: prError = PR_NOT_SOCKET_ERROR; break;
494 case ENXIO: prError = PR_FILE_NOT_FOUND_ERROR; break;
495 case EOPNOTSUPP: prError = PR_NOT_TCP_SOCKET_ERROR; break;
496 #ifdef EOVERFLOW
497 case EOVERFLOW: prError = PR_BUFFER_OVERFLOW_ERROR; break;
498 #endif
499 case EPERM: prError = PR_NO_ACCESS_RIGHTS_ERROR; break;
500 case EPIPE: prError = PR_CONNECT_RESET_ERROR; break;
501 #ifdef EPROTO
502 case EPROTO: prError = PR_IO_ERROR; break;
503 #endif
504 case EPROTONOSUPPORT: prError = PR_PROTOCOL_NOT_SUPPORTED_ERROR; break;
505 case EPROTOTYPE: prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break;
506 case ERANGE: prError = PR_INVALID_METHOD_ERROR; break;
507 case EROFS: prError = PR_READ_ONLY_FILESYSTEM_ERROR; break;
508 case ESPIPE: prError = PR_INVALID_METHOD_ERROR; break;
509 case ETIMEDOUT: prError = PR_IO_TIMEOUT_ERROR; break;
510 #if EWOULDBLOCK != EAGAIN
511 case EWOULDBLOCK: prError = PR_WOULD_BLOCK_ERROR; break;
512 #endif
513 case EXDEV: prError = PR_NOT_SAME_DEVICE_ERROR; break;
515 default: prError = PR_UNKNOWN_ERROR; break;
517 PR_SetError(prError, err);