VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use