1 /* $Id: RTErrConvertFromErrno.cpp $ */
3 * IPRT - Convert errno to iprt status codes.
7 * Copyright (C) 2006-2017 Oracle Corporation
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
28 /*********************************************************************************************************************************
30 *********************************************************************************************************************************/
32 #include "internal/iprt.h"
35 #include <iprt/assert.h>
36 #include <iprt/errno.h>
39 RTDECL(int) RTErrConvertFromErrno(unsigned uNativeCode
)
41 /* very fast check for no error. */
46 * Process error codes.
48 * (Use a switch and not a table since the numbers vary among compilers
49 * and OSes. So we let the compiler switch optimizer handle speed issues.)
51 * This switch is arranged like the Linux i386 errno.h! This switch is mirrored
52 * by RTErrConvertToErrno.
57 case EPERM
: return VERR_ACCESS_DENIED
; /* 1 */
60 case ENOENT
: return VERR_FILE_NOT_FOUND
;
63 case ESRCH
: return VERR_PROCESS_NOT_FOUND
;
66 case EINTR
: return VERR_INTERRUPTED
;
69 case EIO
: return VERR_DEV_IO_ERROR
;
72 case ENXIO
: return VERR_DEV_IO_ERROR
; /** @todo fix this duplicate error */
75 case E2BIG
: return VERR_TOO_MUCH_DATA
;
78 case ENOEXEC
: return VERR_BAD_EXE_FORMAT
;
81 case EBADF
: return VERR_INVALID_HANDLE
;
84 case ECHILD
: return VERR_PROCESS_NOT_FOUND
; /* 10 */ /** @todo fix duplicate error */
87 case EAGAIN
: return VERR_TRY_AGAIN
;
90 case ENOMEM
: return VERR_NO_MEMORY
;
93 case EACCES
: return VERR_ACCESS_DENIED
; /** @todo fix duplicate error */
96 case EFAULT
: return VERR_INVALID_POINTER
;
99 //case ENOTBLK: return VERR_;
102 case EBUSY
: return VERR_RESOURCE_BUSY
;
105 case EEXIST
: return VERR_ALREADY_EXISTS
;
108 case EXDEV
: return VERR_NOT_SAME_DEVICE
;
111 case ENODEV
: return VERR_NOT_SUPPORTED
; /** @todo fix duplicate error */
114 case ENOTDIR
: return VERR_PATH_NOT_FOUND
; /* 20 */
117 case EISDIR
: return VERR_IS_A_DIRECTORY
;
120 case EINVAL
: return VERR_INVALID_PARAMETER
;
123 case ENFILE
: return VERR_TOO_MANY_OPEN_FILES
; /** @todo fix duplicate error */
126 case EMFILE
: return VERR_TOO_MANY_OPEN_FILES
;
129 case ENOTTY
: return VERR_INVALID_FUNCTION
;
132 case ETXTBSY
: return VERR_SHARING_VIOLATION
;
135 case EFBIG
: return VERR_FILE_TOO_BIG
;
138 case ENOSPC
: return VERR_DISK_FULL
;
141 case ESPIPE
: return VERR_SEEK_ON_DEVICE
;
144 case EROFS
: return VERR_WRITE_PROTECT
; /* 30 */
150 case EPIPE
: return VERR_BROKEN_PIPE
;
153 case EDOM
: return VERR_INVALID_PARAMETER
; /** @todo fix duplicate error */
156 case ERANGE
: return VERR_INVALID_PARAMETER
; /** @todo fix duplicate error */
159 case EDEADLK
: return VERR_DEADLOCK
;
162 case ENAMETOOLONG
: return VERR_FILENAME_TOO_LONG
;
165 case ENOLCK
: return VERR_FILE_LOCK_FAILED
;
167 #ifdef ENOSYS /** @todo map this differently on solaris. */
168 case ENOSYS
: return VERR_NOT_SUPPORTED
;
171 case ENOTEMPTY
: return VERR_DIR_NOT_EMPTY
;
174 case ELOOP
: return VERR_TOO_MANY_SYMLINKS
; /* 40 */
178 //case ENOMSG 42 /* No message of desired type */
181 //case EIDRM 43 /* Identifier removed */
184 //case ECHRNG 44 /* Channel number out of range */
187 //case EL2NSYNC 45 /* Level 2 not synchronized */
190 //case EL3HLT 46 /* Level 3 halted */
193 //case EL3RST 47 /* Level 3 reset */
196 //case ELNRNG 48 /* Link number out of range */
199 //case EUNATCH 49 /* Protocol driver not attached */
202 //case ENOCSI 50 /* No CSI structure available */
205 //case EL2HLT 51 /* Level 2 halted */
208 //case EBADE 52 /* Invalid exchange */
211 //case EBADR 53 /* Invalid request descriptor */
214 //case EXFULL 54 /* Exchange full */
217 //case ENOANO 55 /* No anode */
220 //case EBADRQC 56 /* Invalid request code */
223 //case EBADSLT 57 /* Invalid slot */
227 //case EBFONT 59 /* Bad font file format */
230 //case ENOSTR 60 /* Device not a stream */
233 case ENODATA
: return VERR_NO_DATA
;
236 //case ETIME 62 /* Timer expired */
239 //case ENOSR 63 /* Out of streams resources */
242 case ENONET
: return VERR_NET_NO_NETWORK
;
245 //case ENOPKG 65 /* Package not installed */
248 //case EREMOTE 66 /* Object is remote */
251 //case ENOLINK 67 /* Link has been severed */
254 //case EADV 68 /* Advertise error */
257 //case ESRMNT 69 /* Srmount error */
260 //case ECOMM 70 /* Communication error on send */
263 case EPROTO
: return VERR_NET_PROTOCOL_ERROR
;
266 //case EMULTIHOP 72 /* Multihop attempted */
269 //case EDOTDOT 73 /* RFS specific error */
272 //case EBADMSG 74 /* Not a data message */
275 case EOVERFLOW
: return VERR_TOO_MUCH_DATA
; /** @todo fix duplicate error */
278 case ENOTUNIQ
: return VERR_NET_NOT_UNIQUE_NAME
;
281 case EBADFD
: return VERR_INVALID_HANDLE
; /** @todo fix duplicate error? */
284 //case EREMCHG 78 /* Remote address changed */
287 //case ELIBACC 79 /* Can not access a needed shared library */
290 //case ELIBBAD 80 /* Accessing a corrupted shared library */
293 //case ELIBSCN 81 /* .lib section in a.out corrupted */
296 //case ELIBMAX 82 /* Attempting to link in too many shared libraries */
299 //case ELIBEXEC 83 /* Cannot exec a shared library directly */
302 case EILSEQ
: return VERR_NO_TRANSLATION
;
305 case ERESTART
: return VERR_INTERRUPTED
;/** @todo fix duplicate error?*/
308 //case ESTRPIPE 86 /* Streams pipe error */
311 //case EUSERS 87 /* Too many users */
314 case ENOTSOCK
: return VERR_NET_NOT_SOCKET
;
317 case EDESTADDRREQ
: return VERR_NET_DEST_ADDRESS_REQUIRED
;
320 case EMSGSIZE
: return VERR_NET_MSG_SIZE
;
323 case EPROTOTYPE
: return VERR_NET_PROTOCOL_TYPE
;
326 case ENOPROTOOPT
: return VERR_NET_PROTOCOL_NOT_AVAILABLE
;
328 #ifdef EPROTONOSUPPORT
329 case EPROTONOSUPPORT
: return VERR_NET_PROTOCOL_NOT_SUPPORTED
;
331 #ifdef ESOCKTNOSUPPORT
332 case ESOCKTNOSUPPORT
: return VERR_NET_SOCKET_TYPE_NOT_SUPPORTED
;
334 #ifdef EOPNOTSUPP /** @todo map this differently on solaris. */
335 case EOPNOTSUPP
: return VERR_NET_OPERATION_NOT_SUPPORTED
;
338 case EPFNOSUPPORT
: return VERR_NET_PROTOCOL_FAMILY_NOT_SUPPORTED
;
341 case EAFNOSUPPORT
: return VERR_NET_ADDRESS_FAMILY_NOT_SUPPORTED
;
344 case EADDRINUSE
: return VERR_NET_ADDRESS_IN_USE
;
347 case EADDRNOTAVAIL
: return VERR_NET_ADDRESS_NOT_AVAILABLE
;
350 case ENETDOWN
: return VERR_NET_DOWN
;
353 case ENETUNREACH
: return VERR_NET_UNREACHABLE
;
356 case ENETRESET
: return VERR_NET_CONNECTION_RESET
;
359 case ECONNABORTED
: return VERR_NET_CONNECTION_ABORTED
;
362 case ECONNRESET
: return VERR_NET_CONNECTION_RESET_BY_PEER
;
365 case ENOBUFS
: return VERR_NET_NO_BUFFER_SPACE
;
368 case EISCONN
: return VERR_NET_ALREADY_CONNECTED
;
371 case ENOTCONN
: return VERR_NET_NOT_CONNECTED
;
374 case ESHUTDOWN
: return VERR_NET_SHUTDOWN
;
377 case ETOOMANYREFS
: return VERR_NET_TOO_MANY_REFERENCES
;
380 case ETIMEDOUT
: return VERR_TIMEOUT
;
383 case ECONNREFUSED
: return VERR_NET_CONNECTION_REFUSED
;
386 case EHOSTDOWN
: return VERR_NET_HOST_DOWN
;
389 case EHOSTUNREACH
: return VERR_NET_HOST_UNREACHABLE
;
392 case EALREADY
: return VERR_NET_ALREADY_IN_PROGRESS
;
395 case EINPROGRESS
: return VERR_NET_IN_PROGRESS
;
398 //case ESTALE 116 /* Stale NFS file handle */
401 //case EUCLEAN 117 /* Structure needs cleaning */
404 //case ENOTNAM 118 /* Not a XENIX named type file */
407 //case ENAVAIL 119 /* No XENIX semaphores available */
410 //case EISNAM 120 /* Is a named type file */
413 //case EREMOTEIO 121 /* Remote I/O error */
416 case EDQUOT
: return VERR_DISK_FULL
; /** @todo fix duplicate error */
419 case ENOMEDIUM
: return VERR_MEDIA_NOT_PRESENT
;
422 case EMEDIUMTYPE
: return VERR_MEDIA_NOT_RECOGNIZED
;
424 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
425 case EWOULDBLOCK
: return VERR_TRY_AGAIN
;
431 case EPROCLIM
: return VERR_MAX_PROCS_REACHED
;
434 # if EDOOFUS != EINVAL
435 case EDOOFUS
: return VERR_INTERNAL_ERROR
;
440 case ENOTSUP
: return VERR_NOT_SUPPORTED
;
442 # if ENOTSUP != EOPNOTSUPP
443 case ENOTSUP
: return VERR_NOT_SUPPORTED
;
448 AssertLogRelMsgFailed(("Unhandled error code %d\n", uNativeCode
));
449 return VERR_UNRESOLVED_ERROR
;
452 RT_EXPORT_SYMBOL(RTErrConvertFromErrno
);