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