1 /* $Id: RTErrConvertFromErrno.cpp 23517 2007-08-07 17:07:59Z umoeller $ */
3 * innotek Portable Runtime - Convert errno to iprt status codes.
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
19 /*******************************************************************************
21 *******************************************************************************/
22 #include "RTErrConvertFromErrno.h"
23 #include "const_defines.h"
24 #include "func_defines.h"
28 int RTErrConvertFromErrno(unsigned uNativeCode
)
30 /* very fast check for no error. */
35 * Process error codes.
37 * (Use a switch and not a table since the numbers vary among compilers
38 * and OSes. So we let the compiler switch optimizer handle speed issues.)
40 * This switch is arranged like the Linux i386 errno.h!
45 case EPERM
: return VERR_ACCESS_DENIED
; /* 1 */
48 case ENOENT
: return VERR_FILE_NOT_FOUND
;
51 case ESRCH
: return VERR_PROCESS_NOT_FOUND
;
54 case EINTR
: return VERR_INTERRUPTED
;
57 case EIO
: return VERR_DEV_IO_ERROR
;
60 case ENXIO
: return VERR_DEV_IO_ERROR
;
63 case E2BIG
: return VERR_TOO_MUCH_DATA
;
66 case ENOEXEC
: return VERR_BAD_EXE_FORMAT
;
69 case EBADF
: return VERR_INVALID_HANDLE
;
72 case ECHILD
: return VERR_PROCESS_NOT_FOUND
; //... /* 10 */
75 case EAGAIN
: return VERR_TRY_AGAIN
;
78 case ENOMEM
: return VERR_NO_MEMORY
;
81 case EACCES
: return VERR_ACCESS_DENIED
;
84 case EFAULT
: return VERR_INVALID_POINTER
;
87 //case ENOTBLK: return VERR_;
90 case EBUSY
: return VERR_DEV_IO_ERROR
;
93 case EEXIST
: return VERR_ALREADY_EXISTS
;
96 case EXDEV
: return VERR_NOT_SAME_DEVICE
;
99 case ENODEV
: return VERR_NOT_SUPPORTED
;
102 case ENOTDIR
: return VERR_PATH_NOT_FOUND
; /* 20 */
105 case EISDIR
: return VERR_IS_A_DIRECTORY
;
108 case EINVAL
: return VERR_INVALID_PARAMETER
;
111 case ENFILE
: return VERR_TOO_MANY_OPEN_FILES
;
114 case EMFILE
: return VERR_TOO_MANY_OPEN_FILES
;
117 case ENOTTY
: return VERR_INVALID_FUNCTION
;
120 case ETXTBSY
: return VERR_SHARING_VIOLATION
;
123 case EFBIG
: return VERR_FILE_TOO_BIG
;
126 case ENOSPC
: return VERR_DISK_FULL
;
129 case ESPIPE
: return VERR_SEEK_ON_DEVICE
;
132 case EROFS
: return VERR_WRITE_PROTECT
; /* 30 */
138 case EPIPE
: return VERR_BROKEN_PIPE
;
141 case EDOM
: return VERR_INVALID_PARAMETER
;
144 case ERANGE
: return VERR_INVALID_PARAMETER
;
147 case EDEADLK
: return VERR_DEADLOCK
;
150 case ENAMETOOLONG
: return VERR_FILENAME_TOO_LONG
;
153 case ENOLCK
: return VERR_FILE_LOCK_FAILED
;
156 case ENOSYS
: return VERR_NOT_SUPPORTED
;
159 case ENOTEMPTY
: return VERR_DIR_NOT_EMPTY
;
162 case ELOOP
: return VERR_TOO_MANY_SYMLINKS
; /* 40 */
166 //case ENOMSG 42 /* No message of desired type */
169 //case EIDRM 43 /* Identifier removed */
172 //case ECHRNG 44 /* Channel number out of range */
175 //case EL2NSYNC 45 /* Level 2 not synchronized */
178 //case EL3HLT 46 /* Level 3 halted */
181 //case EL3RST 47 /* Level 3 reset */
184 //case ELNRNG 48 /* Link number out of range */
187 //case EUNATCH 49 /* Protocol driver not attached */
190 //case ENOCSI 50 /* No CSI structure available */
193 //case EL2HLT 51 /* Level 2 halted */
196 //case EBADE 52 /* Invalid exchange */
199 //case EBADR 53 /* Invalid request descriptor */
202 //case EXFULL 54 /* Exchange full */
205 //case ENOANO 55 /* No anode */
208 //case EBADRQC 56 /* Invalid request code */
211 //case EBADSLT 57 /* Invalid slot */
215 //case EBFONT 59 /* Bad font file format */
218 //case ENOSTR 60 /* Device not a stream */
221 case ENODATA
: return VERR_NO_DATA
;
224 //case ETIME 62 /* Timer expired */
227 //case ENOSR 63 /* Out of streams resources */
230 case ENONET
: return VERR_NET_NO_NETWORK
;
233 //case ENOPKG 65 /* Package not installed */
236 //case EREMOTE 66 /* Object is remote */
239 //case ENOLINK 67 /* Link has been severed */
242 //case EADV 68 /* Advertise error */
245 //case ESRMNT 69 /* Srmount error */
248 //case ECOMM 70 /* Communication error on send */
251 //case EPROTO 71 /* Protocol error */
254 //case EMULTIHOP 72 /* Multihop attempted */
257 //case EDOTDOT 73 /* RFS specific error */
260 //case EBADMSG 74 /* Not a data message */
263 case EOVERFLOW
: return VERR_TOO_MUCH_DATA
;
266 case ENOTUNIQ
: return VERR_NET_NOT_UNIQUE_NAME
;
269 case EBADFD
: return VERR_INVALID_HANDLE
;
272 //case EREMCHG 78 /* Remote address changed */
275 //case ELIBACC 79 /* Can not access a needed shared library */
278 //case ELIBBAD 80 /* Accessing a corrupted shared library */
281 //case ELIBSCN 81 /* .lib section in a.out corrupted */
284 //case ELIBMAX 82 /* Attempting to link in too many shared libraries */
287 //case ELIBEXEC 83 /* Cannot exec a shared library directly */
290 case EILSEQ
: return VERR_NO_TRANSLATION
;
293 case ERESTART
: return VERR_INTERRUPTED
;
296 //case ESTRPIPE 86 /* Streams pipe error */
299 //case EUSERS 87 /* Too many users */
302 case ENOTSOCK
: return VERR_NET_NOT_SOCKET
;
305 case EDESTADDRREQ
: return VERR_NET_DEST_ADDRESS_REQUIRED
;
308 case EMSGSIZE
: return VERR_NET_MSG_SIZE
;
311 case EPROTOTYPE
: return VERR_NET_PROTOCOL_TYPE
;
314 case ENOPROTOOPT
: return VERR_NET_PROTOCOL_NOT_AVAILABLE
;
316 #ifdef EPROTONOSUPPORT
317 case EPROTONOSUPPORT
: return VERR_NET_PROTOCOL_NOT_SUPPORTED
;
319 #ifdef ESOCKTNOSUPPORT
320 case ESOCKTNOSUPPORT
: return VERR_NET_SOCKET_TYPE_NOT_SUPPORTED
;
323 case EOPNOTSUPP
: return VERR_NET_OPERATION_NOT_SUPPORTED
;
326 case EPFNOSUPPORT
: return VERR_NET_PROTOCOL_FAMILY_NOT_SUPPORTED
;
329 case EAFNOSUPPORT
: return VERR_NET_ADDRESS_FAMILY_NOT_SUPPORTED
;
332 case EADDRINUSE
: return VERR_NET_ADDRESS_IN_USE
;
335 case EADDRNOTAVAIL
: return VERR_NET_ADDRESS_NOT_AVAILABLE
;
338 case ENETDOWN
: return VERR_NET_DOWN
;
341 case ENETUNREACH
: return VERR_NET_UNREACHABLE
;
344 case ENETRESET
: return VERR_NET_CONNECTION_RESET
;
347 case ECONNABORTED
: return VERR_NET_CONNECTION_ABORTED
;
350 case ECONNRESET
: return VERR_NET_CONNECTION_RESET_BY_PEER
;
353 case ENOBUFS
: return VERR_NET_NO_BUFFER_SPACE
;
356 case EISCONN
: return VERR_NET_ALREADY_CONNECTED
;
359 case ENOTCONN
: return VERR_NET_NOT_CONNECTED
;
362 case ESHUTDOWN
: return VERR_NET_SHUTDOWN
;
365 case ETOOMANYREFS
: return VERR_NET_TOO_MANY_REFERENCES
;
368 case ETIMEDOUT
: return VERR_TIMEOUT
;
371 case ECONNREFUSED
: return VERR_NET_CONNECTION_REFUSED
;
374 case EHOSTDOWN
: return VERR_NET_HOST_DOWN
;
377 case EHOSTUNREACH
: return VERR_NET_HOST_UNREACHABLE
;
380 case EALREADY
: return VERR_NET_ALREADY_IN_PROGRESS
;
383 case EINPROGRESS
: return VERR_NET_IN_PROGRESS
;
386 //case ESTALE 116 /* Stale NFS file handle */
389 //case EUCLEAN 117 /* Structure needs cleaning */
392 //case ENOTNAM 118 /* Not a XENIX named type file */
395 //case ENAVAIL 119 /* No XENIX semaphores available */
398 //case EISNAM 120 /* Is a named type file */
401 //case EREMOTEIO 121 /* Remote I/O error */
404 case EDQUOT
: return VERR_DISK_FULL
;
407 case ENOMEDIUM
: return VERR_MEDIA_NOT_PRESENT
;
410 case EMEDIUMTYPE
: return VERR_MEDIA_NOT_RECOGNIZED
;
416 case EPROCLIM
: return VERR_MAX_PROCS_REACHED
;
420 AssertMsgFailed(("Unhandled error code %d\n", uNativeCode
));
421 return VERR_UNRESOLVED_ERROR
;