VirtualBox

source: vbox/trunk/src/VBox/Runtime/errmsg.cpp@ 5285

Last change on this file since 5285 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1/* $Id: errmsg.cpp 4071 2007-08-07 17:07:59Z 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
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#include <iprt/err.h>
22#include <iprt/asm.h>
23#include <iprt/string.h>
24#include <iprt/err.h>
25#include <VBox/err.h>
26
27
28/*******************************************************************************
29* Global Variables *
30*******************************************************************************/
31/** Array of messages.
32 * The data is generated by a sed script.
33 */
34static const RTSTATUSMSG g_aStatusMsgs[] =
35{
36#include "errmsgdata.h"
37 { NULL, NULL, NULL, 0 }
38};
39
40
41/** Temporary buffers to format unknown messages in.
42 * @{
43 */
44static char g_aszUnknownStr[4][64];
45static RTSTATUSMSG g_aUnknownMsgs[4] =
46{
47 { &g_aszUnknownStr[0][0], &g_aszUnknownStr[0][0], &g_aszUnknownStr[0][0], 0 },
48 { &g_aszUnknownStr[1][0], &g_aszUnknownStr[1][0], &g_aszUnknownStr[1][0], 0 },
49 { &g_aszUnknownStr[2][0], &g_aszUnknownStr[2][0], &g_aszUnknownStr[2][0], 0 },
50 { &g_aszUnknownStr[3][0], &g_aszUnknownStr[3][0], &g_aszUnknownStr[3][0], 0 }
51};
52/** Last used index in g_aUnknownMsgs. */
53static volatile uint32_t g_iUnknownMsgs;
54/** @} */
55
56
57/**
58 * Get the message corresponding to a given status code.
59 *
60 * @returns Pointer to read-only message description.
61 * @param rc The status code.
62 */
63RTDECL(PCRTSTATUSMSG) RTErrGet(int rc)
64{
65 unsigned iFound = ~0;
66 unsigned i;
67 for (i = 0; i < ELEMENTS(g_aStatusMsgs); i++)
68 {
69 if (g_aStatusMsgs[i].iCode == rc)
70 {
71 /*
72 * Found a match.
73 * Since this isn't a unique key, we must check that it's not
74 * one of those start/end #defines before we return.
75 */
76 if ( !strstr(g_aStatusMsgs[i].pszDefine, "FIRST")
77 && !strstr(g_aStatusMsgs[i].pszDefine, "LAST"))
78 return &g_aStatusMsgs[i];
79 iFound = i;
80 }
81 }
82 if (iFound != ~0U)
83 return &g_aStatusMsgs[iFound];
84
85 /*
86 * Need to use the temporary stuff.
87 */
88 int iMsg = ASMAtomicXchgU32(&g_iUnknownMsgs, (g_iUnknownMsgs + 1) % ELEMENTS(g_aUnknownMsgs));
89 RTStrPrintf(&g_aszUnknownStr[iMsg][0], sizeof(g_aszUnknownStr[iMsg]), "Unknown Status 0x%X\n", rc);
90 return &g_aUnknownMsgs[iMsg];
91}
92
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