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