VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/err/RTErrConvertToErrno.cpp@ 7689

Last change on this file since 7689 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 12.7 KB
Line 
1/* $Rev: 5999 $ */
2/** @file
3 * innotek Portable Runtime - Convert iprt status codes to errno.
4 */
5
6/*
7 * Copyright (C) 2007 innotek GmbH
8 *
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.
16 *
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.
22 *
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.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/err.h>
32#include <iprt/assert.h>
33#include <iprt/err.h>
34
35#if defined(RT_OS_DARWIN) && defined(KERNEL)
36# include <sys/errno.h>
37#elif defined(RT_OS_LINUX) && defined(__KERNEL__)
38# include <linux/errno.h>
39#else
40# include <errno.h>
41#endif
42
43
44RTDECL(int) RTErrConvertToErrno(int iErr)
45{
46 /* very fast check for no error. */
47 if (RT_SUCCESS(iErr))
48 return 0;
49
50 /*
51 * Process error codes.
52 *
53 * Try to reverse the behaviour of RTErrConvertFromErrno as far
54 * as possible.
55 *
56 * @note I am very impressed by the length of some of these
57 * error codes - we have obviously learnt something from
58 * Unix's failings :)
59 */
60 switch (iErr)
61 {
62#ifdef EPERM
63 case VERR_ACCESS_DENIED: return EPERM;
64#endif
65#ifdef ENOENT
66 case VERR_FILE_NOT_FOUND: return ENOENT;
67#endif
68#ifdef ESRCH
69 case VERR_PROCESS_NOT_FOUND: return ESRCH;
70#endif
71#ifdef EINTR
72 case VERR_INTERRUPTED: return EINTR;
73#endif
74#ifdef EIO
75 case VERR_DEV_IO_ERROR: return EIO;
76#endif
77#ifdef ENXIO
78 //case VERR_DEV_IO_ERROR: return ENXIO;
79#endif
80#ifdef E2BIG
81 case VERR_TOO_MUCH_DATA: return E2BIG;
82#endif
83#ifdef ENOEXEC
84 case VERR_BAD_EXE_FORMAT: return ENOEXEC;
85#endif
86#ifdef EBADF
87 case VERR_INVALID_HANDLE: return EBADF;
88#endif
89#ifdef ECHILD
90 //case VERR_PROCESS_NOT_FOUND: return ECHILD;
91#endif
92#ifdef EAGAIN
93 case VERR_TRY_AGAIN: return EAGAIN;
94#endif
95#ifdef ENOMEM
96 case VERR_NO_MEMORY: return ENOMEM;
97#endif
98#ifdef EACCES
99 //case VERR_ACCESS_DENIED: return EACCES;
100#endif
101#ifdef EFAULT
102 case VERR_INVALID_POINTER: return EFAULT;
103#endif
104#ifdef ENOTBLK
105 //case ENOTBLK: return VERR_;
106#endif
107#ifdef EBUSY
108 //case VERR_DEV_IO_ERROR: return EBUSY;
109#endif
110#ifdef EEXIST
111 case VERR_ALREADY_EXISTS: return EEXIST;
112#endif
113#ifdef EXDEV
114 case VERR_NOT_SAME_DEVICE: return EXDEV;
115#endif
116#ifdef ENODEV
117 //case VERR_NOT_SUPPORTED: return ENODEV;
118#endif
119#ifdef ENOTDIR
120 case VERR_PATH_NOT_FOUND: return ENOENT;
121#endif
122#ifdef EISDIR
123 case VERR_IS_A_DIRECTORY: return EISDIR;
124#endif
125#ifdef EINVAL
126 case VERR_INVALID_PARAMETER: return EINVAL;
127#endif
128#ifdef ENFILE
129 case VERR_TOO_MANY_OPEN_FILES: return ENFILE;
130#endif
131#ifdef EMFILE
132 //case VERR_TOO_MANY_OPEN_FILES: return EMFILE;
133#endif
134#ifdef ENOTTY
135 case VERR_INVALID_FUNCTION: return ENOTTY;
136#endif
137#ifdef ETXTBSY
138 case VERR_SHARING_VIOLATION: return ETXTBSY;
139#endif
140#ifdef EFBIG
141 case VERR_FILE_TOO_BIG: return EFBIG;
142#endif
143#ifdef ENOSPC
144 case VERR_DISK_FULL: return ENOSPC;
145#endif
146#ifdef ESPIPE
147 case VERR_SEEK_ON_DEVICE: return ESPIPE;
148#endif
149#ifdef EROFS
150 case VERR_WRITE_PROTECT: return EROFS;
151#endif
152#ifdef EMLINK
153 //case EMLINK:
154#endif
155#ifdef EPIPE
156 case VERR_BROKEN_PIPE: return EPIPE;
157#endif
158#ifdef EDOM
159 //case VERR_INVALID_PARAMETER: return EDOM;
160#endif
161#ifdef ERANGE
162 //case VERR_INVALID_PARAMETER: return ERANGE;
163#endif
164#ifdef EDEADLK
165 case VERR_DEADLOCK: return EDEADLK;
166#endif
167#ifdef ENAMETOOLONG
168 case VERR_FILENAME_TOO_LONG: return ENAMETOOLONG;
169#endif
170#ifdef ENOLCK
171 case VERR_FILE_LOCK_FAILED: return ENOLCK;
172#endif
173#ifdef ENOSYS
174 case VERR_NOT_SUPPORTED: return ENOSYS;
175#endif
176#ifdef ENOTEMPTY
177 case VERR_DIR_NOT_EMPTY: return ENOTEMPTY;
178#endif
179#ifdef ELOOP
180 case VERR_TOO_MANY_SYMLINKS: return ELOOP;
181#endif
182 //41??
183#ifdef ENOMSG
184 //case ENOMSG 42 /* No message of desired type */
185#endif
186#ifdef EIDRM
187 //case EIDRM 43 /* Identifier removed */
188#endif
189#ifdef ECHRNG
190 //case ECHRNG 44 /* Channel number out of range */
191#endif
192#ifdef EL2NSYNC
193 //case EL2NSYNC 45 /* Level 2 not synchronized */
194#endif
195#ifdef EL3HLT
196 //case EL3HLT 46 /* Level 3 halted */
197#endif
198#ifdef EL3RST
199 //case EL3RST 47 /* Level 3 reset */
200#endif
201#ifdef ELNRNG
202 //case ELNRNG 48 /* Link number out of range */
203#endif
204#ifdef EUNATCH
205 //case EUNATCH 49 /* Protocol driver not attached */
206#endif
207#ifdef ENOCSI
208 //case ENOCSI 50 /* No CSI structure available */
209#endif
210#ifdef EL2HLT
211 //case EL2HLT 51 /* Level 2 halted */
212#endif
213#ifdef EBADE
214 //case EBADE 52 /* Invalid exchange */
215#endif
216#ifdef EBADR
217 //case EBADR 53 /* Invalid request descriptor */
218#endif
219#ifdef EXFULL
220 //case EXFULL 54 /* Exchange full */
221#endif
222#ifdef ENOANO
223 //case ENOANO 55 /* No anode */
224#endif
225#ifdef EBADRQC
226 //case EBADRQC 56 /* Invalid request code */
227#endif
228#ifdef EBADSLT
229 //case EBADSLT 57 /* Invalid slot */
230#endif
231 //case 58:
232#ifdef EBFONT
233 //case EBFONT 59 /* Bad font file format */
234#endif
235#ifdef ENOSTR
236 //case ENOSTR 60 /* Device not a stream */
237#endif
238#ifdef ENODATA
239 case VERR_NO_DATA: return ENODATA;
240#endif
241#ifdef ETIME
242 //case ETIME 62 /* Timer expired */
243#endif
244#ifdef ENOSR
245 //case ENOSR 63 /* Out of streams resources */
246#endif
247#ifdef ENONET
248 case VERR_NET_NO_NETWORK: return ENONET;
249#endif
250#ifdef ENOPKG
251 //case ENOPKG 65 /* Package not installed */
252#endif
253#ifdef EREMOTE
254 //case EREMOTE 66 /* Object is remote */
255#endif
256#ifdef ENOLINK
257 //case ENOLINK 67 /* Link has been severed */
258#endif
259#ifdef EADV
260 //case EADV 68 /* Advertise error */
261#endif
262#ifdef ESRMNT
263 //case ESRMNT 69 /* Srmount error */
264#endif
265#ifdef ECOMM
266 //case ECOMM 70 /* Communication error on send */
267#endif
268#ifdef EPROTO
269 //case EPROTO 71 /* Protocol error */
270#endif
271#ifdef EMULTIHOP
272 //case EMULTIHOP 72 /* Multihop attempted */
273#endif
274#ifdef EDOTDOT
275 //case EDOTDOT 73 /* RFS specific error */
276#endif
277#ifdef EBADMSG
278 //case EBADMSG 74 /* Not a data message */
279#endif
280#ifdef EOVERFLOW
281 //case VERR_TOO_MUCH_DATA: return EOVERFLOW;
282#endif
283#ifdef ENOTUNIQ
284 case VERR_NET_NOT_UNIQUE_NAME: return ENOTUNIQ;
285#endif
286#ifdef EBADFD
287 //case VERR_INVALID_HANDLE: return EBADFD;
288#endif
289#ifdef EREMCHG
290 //case EREMCHG 78 /* Remote address changed */
291#endif
292#ifdef ELIBACC
293 //case ELIBACC 79 /* Can not access a needed shared library */
294#endif
295#ifdef ELIBBAD
296 //case ELIBBAD 80 /* Accessing a corrupted shared library */
297#endif
298#ifdef ELIBSCN
299 //case ELIBSCN 81 /* .lib section in a.out corrupted */
300#endif
301#ifdef ELIBMAX
302 //case ELIBMAX 82 /* Attempting to link in too many shared libraries */
303#endif
304#ifdef ELIBEXEC
305 //case ELIBEXEC 83 /* Cannot exec a shared library directly */
306#endif
307#ifdef EILSEQ
308 case VERR_NO_TRANSLATION: return EILSEQ;
309#endif
310#ifdef ERESTART
311 //case VERR_INTERRUPTED: return ERESTART;
312#endif
313#ifdef ESTRPIPE
314 //case ESTRPIPE 86 /* Streams pipe error */
315#endif
316#ifdef EUSERS
317 //case EUSERS 87 /* Too many users */
318#endif
319#ifdef ENOTSOCK
320 case VERR_NET_NOT_SOCKET: return ENOTSOCK;
321#endif
322#ifdef EDESTADDRREQ
323 case VERR_NET_DEST_ADDRESS_REQUIRED: return EDESTADDRREQ;
324#endif
325#ifdef EMSGSIZE
326 case VERR_NET_MSG_SIZE: return EMSGSIZE;
327#endif
328#ifdef EPROTOTYPE
329 case VERR_NET_PROTOCOL_TYPE: return EPROTOTYPE;
330#endif
331#ifdef ENOPROTOOPT
332 case VERR_NET_PROTOCOL_NOT_AVAILABLE: return ENOPROTOOPT;
333#endif
334#ifdef EPROTONOSUPPORT
335 case VERR_NET_PROTOCOL_NOT_SUPPORTED: return EPROTONOSUPPORT;
336#endif
337#ifdef ESOCKTNOSUPPORT
338 case VERR_NET_SOCKET_TYPE_NOT_SUPPORTED: return ESOCKTNOSUPPORT;
339#endif
340#ifdef EOPNOTSUPP
341 case VERR_NET_OPERATION_NOT_SUPPORTED: return EOPNOTSUPP;
342#endif
343#ifdef EPFNOSUPPORT
344 case VERR_NET_PROTOCOL_FAMILY_NOT_SUPPORTED: return EPFNOSUPPORT;
345#endif
346#ifdef EAFNOSUPPORT
347 case VERR_NET_ADDRESS_FAMILY_NOT_SUPPORTED: return EAFNOSUPPORT;
348#endif
349#ifdef EADDRINUSE
350 case VERR_NET_ADDRESS_IN_USE: return EADDRINUSE;
351#endif
352#ifdef EADDRNOTAVAIL
353 case VERR_NET_ADDRESS_NOT_AVAILABLE: return EADDRNOTAVAIL;
354#endif
355#ifdef ENETDOWN
356 case VERR_NET_DOWN: return ENETDOWN;
357#endif
358#ifdef ENETUNREACH
359 case VERR_NET_UNREACHABLE: return ENETUNREACH;
360#endif
361#ifdef ENETRESET
362 case VERR_NET_CONNECTION_RESET: return ENETRESET;
363#endif
364#ifdef ECONNABORTED
365 case VERR_NET_CONNECTION_ABORTED: return ECONNABORTED;
366#endif
367#ifdef ECONNRESET
368 case VERR_NET_CONNECTION_RESET_BY_PEER: return ECONNRESET;
369#endif
370#ifdef ENOBUFS
371 case VERR_NET_NO_BUFFER_SPACE: return ENOBUFS;
372#endif
373#ifdef EISCONN
374 case VERR_NET_ALREADY_CONNECTED: return EISCONN;
375#endif
376#ifdef ENOTCONN
377 case VERR_NET_NOT_CONNECTED: return ENOTCONN;
378#endif
379#ifdef ESHUTDOWN
380 case VERR_NET_SHUTDOWN: return ESHUTDOWN;
381#endif
382#ifdef ETOOMANYREFS
383 case VERR_NET_TOO_MANY_REFERENCES: return ETOOMANYREFS;
384#endif
385#ifdef ETIMEDOUT
386 case VERR_TIMEOUT: return ETIMEDOUT;
387#endif
388#ifdef ECONNREFUSED
389 case VERR_NET_CONNECTION_REFUSED: return ECONNREFUSED;
390#endif
391#ifdef EHOSTDOWN
392 case VERR_NET_HOST_DOWN: return EHOSTDOWN;
393#endif
394#ifdef EHOSTUNREACH
395 case VERR_NET_HOST_UNREACHABLE: return EHOSTUNREACH;
396#endif
397#ifdef EALREADY
398 case VERR_NET_ALREADY_IN_PROGRESS: return EALREADY;
399#endif
400#ifdef EINPROGRESS
401 case VERR_NET_IN_PROGRESS: return EINPROGRESS;
402#endif
403#ifdef ESTALE
404 //case ESTALE 116 /* Stale NFS file handle */
405#endif
406#ifdef EUCLEAN
407 //case EUCLEAN 117 /* Structure needs cleaning */
408#endif
409#ifdef ENOTNAM
410 //case ENOTNAM 118 /* Not a XENIX named type file */
411#endif
412#ifdef ENAVAIL
413 //case ENAVAIL 119 /* No XENIX semaphores available */
414#endif
415#ifdef EISNAM
416 //case EISNAM 120 /* Is a named type file */
417#endif
418#ifdef EREMOTEIO
419 //case EREMOTEIO 121 /* Remote I/O error */
420#endif
421#ifdef EDQUOT
422 //case VERR_DISK_FULL: return EDQUOT;
423#endif
424#ifdef ENOMEDIUM
425 case VERR_MEDIA_NOT_PRESENT: return ENOMEDIUM;
426#endif
427#ifdef EMEDIUMTYPE
428 case VERR_MEDIA_NOT_RECOGNIZED: return EMEDIUMTYPE;
429#endif
430
431 /* Non-linux */
432
433#ifdef EPROCLIM
434 case VERR_MAX_PROCS_REACHED: return EPROCLIM;
435#endif
436
437 default:
438 AssertMsgFailed(("Unhandled error code %Rrc\n", iErr));
439 return EPROTO;
440 }
441}
442
443#if defined(RT_OS_LINUX) && defined(IN_MODULE)
444/*
445 * When we build this in the Linux kernel module, we wish to make the
446 * symbols available to other modules as well.
447 */
448# include "the-linux-kernel.h"
449EXPORT_SYMBOL(RTErrConvertToErrno);
450#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette