VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

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