VirtualBox

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

Last change on this file since 32568 was 31316, checked in by vboxsync, 14 years ago

fix typo

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