VirtualBox

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

Last change on this file since 57358 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

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