1 | /* $Id: errmsg.cpp 3672 2007-07-17 12:39:30Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * innotek Portable Runtime - Status code messages.
|
---|
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 as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*******************************************************************************
|
---|
23 | * Header Files *
|
---|
24 | *******************************************************************************/
|
---|
25 | #include <iprt/err.h>
|
---|
26 | #include <iprt/asm.h>
|
---|
27 | #include <iprt/string.h>
|
---|
28 | #include <iprt/err.h>
|
---|
29 | #include <VBox/err.h>
|
---|
30 |
|
---|
31 |
|
---|
32 | /*******************************************************************************
|
---|
33 | * Global Variables *
|
---|
34 | *******************************************************************************/
|
---|
35 | /** Array of messages.
|
---|
36 | * The data is generated by a sed script.
|
---|
37 | */
|
---|
38 | static const RTSTATUSMSG g_aStatusMsgs[] =
|
---|
39 | {
|
---|
40 | #include "errmsgdata.h"
|
---|
41 | { NULL, NULL, NULL, 0 }
|
---|
42 | };
|
---|
43 |
|
---|
44 |
|
---|
45 | /** Temporary buffers to format unknown messages in.
|
---|
46 | * @{
|
---|
47 | */
|
---|
48 | static char g_aszUnknownStr[4][64];
|
---|
49 | static RTSTATUSMSG g_aUnknownMsgs[4] =
|
---|
50 | {
|
---|
51 | { &g_aszUnknownStr[0][0], &g_aszUnknownStr[0][0], &g_aszUnknownStr[0][0], 0 },
|
---|
52 | { &g_aszUnknownStr[1][0], &g_aszUnknownStr[1][0], &g_aszUnknownStr[1][0], 0 },
|
---|
53 | { &g_aszUnknownStr[2][0], &g_aszUnknownStr[2][0], &g_aszUnknownStr[2][0], 0 },
|
---|
54 | { &g_aszUnknownStr[3][0], &g_aszUnknownStr[3][0], &g_aszUnknownStr[3][0], 0 }
|
---|
55 | };
|
---|
56 | /** Last used index in g_aUnknownMsgs. */
|
---|
57 | static volatile uint32_t g_iUnknownMsgs;
|
---|
58 | /** @} */
|
---|
59 |
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Get the message corresponding to a given status code.
|
---|
63 | *
|
---|
64 | * @returns Pointer to read-only message description.
|
---|
65 | * @param rc The status code.
|
---|
66 | */
|
---|
67 | RTDECL(PCRTSTATUSMSG) RTErrGet(int rc)
|
---|
68 | {
|
---|
69 | unsigned iFound = ~0;
|
---|
70 | unsigned i;
|
---|
71 | for (i = 0; i < ELEMENTS(g_aStatusMsgs); i++)
|
---|
72 | {
|
---|
73 | if (g_aStatusMsgs[i].iCode == rc)
|
---|
74 | {
|
---|
75 | /*
|
---|
76 | * Found a match.
|
---|
77 | * Since this isn't a unique key, we must check that it's not
|
---|
78 | * one of those start/end #defines before we return.
|
---|
79 | */
|
---|
80 | if ( !strstr(g_aStatusMsgs[i].pszDefine, "FIRST")
|
---|
81 | && !strstr(g_aStatusMsgs[i].pszDefine, "LAST"))
|
---|
82 | return &g_aStatusMsgs[i];
|
---|
83 | iFound = i;
|
---|
84 | }
|
---|
85 | }
|
---|
86 | if (iFound != ~0U)
|
---|
87 | return &g_aStatusMsgs[iFound];
|
---|
88 |
|
---|
89 | /*
|
---|
90 | * Need to use the temporary stuff.
|
---|
91 | */
|
---|
92 | int iMsg = ASMAtomicXchgU32(&g_iUnknownMsgs, (g_iUnknownMsgs + 1) % ELEMENTS(g_aUnknownMsgs));
|
---|
93 | RTStrPrintf(&g_aszUnknownStr[iMsg][0], sizeof(g_aszUnknownStr[iMsg]), "Unknown Status 0x%X\n", rc);
|
---|
94 | return &g_aUnknownMsgs[iMsg];
|
---|
95 | }
|
---|
96 |
|
---|