VirtualBox

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

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