VirtualBox

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

Last change on this file since 62477 was 62477, checked in by vboxsync, 8 years ago

(C) 2016

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