1 | /* $Id: message.cpp 24826 2009-11-20 14:41:26Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Error reporting to standard error.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 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 | * Header Files *
|
---|
33 | *******************************************************************************/
|
---|
34 | #include "internal/iprt.h"
|
---|
35 | #include <iprt/message.h>
|
---|
36 |
|
---|
37 | #include <iprt/path.h>
|
---|
38 | #include <iprt/string.h>
|
---|
39 | #include <iprt/stream.h>
|
---|
40 | #include "internal/process.h"
|
---|
41 |
|
---|
42 |
|
---|
43 | RTDECL(int) RTMsgError(const char *pszFormat, ...)
|
---|
44 | {
|
---|
45 | va_list va;
|
---|
46 | va_start(va, pszFormat);
|
---|
47 | int rc = RTMsgErrorV(pszFormat, va);
|
---|
48 | va_end(va);
|
---|
49 | return rc;
|
---|
50 | }
|
---|
51 | RT_EXPORT_SYMBOL(RTMsgError);
|
---|
52 |
|
---|
53 |
|
---|
54 | RTDECL(int) RTMsgErrorV(const char *pszFormat, va_list va)
|
---|
55 | {
|
---|
56 | if ( !*pszFormat
|
---|
57 | || !strcmp(pszFormat, "\n"))
|
---|
58 | RTStrmPrintf(g_pStdErr, "\n");
|
---|
59 | else
|
---|
60 | {
|
---|
61 | char *pszMsg;
|
---|
62 | ssize_t cch = RTStrAPrintfV(&pszMsg, pszFormat, va);
|
---|
63 | if (cch >= 0)
|
---|
64 | {
|
---|
65 | /* print it line by line. */
|
---|
66 | char *psz = pszMsg;
|
---|
67 | do
|
---|
68 | {
|
---|
69 | char *pszEnd = strchr(psz, '\n');
|
---|
70 | if (!pszEnd)
|
---|
71 | {
|
---|
72 | RTStrmPrintf(g_pStdErr, "%s: error: %s\n", &g_szrtProcExePath[g_offrtProcName], psz);
|
---|
73 | break;
|
---|
74 | }
|
---|
75 | if (pszEnd == psz)
|
---|
76 | RTStrmPrintf(g_pStdErr, "\n");
|
---|
77 | else
|
---|
78 | {
|
---|
79 | *pszEnd = '\0';
|
---|
80 | RTStrmPrintf(g_pStdErr, "%s: error: %s\n", &g_szrtProcExePath[g_offrtProcName], psz);
|
---|
81 | }
|
---|
82 | psz = pszEnd + 1;
|
---|
83 | } while (*psz);
|
---|
84 | RTStrFree(pszMsg);
|
---|
85 | }
|
---|
86 | else
|
---|
87 | {
|
---|
88 | /* Simple fallback for handling out-of-memory conditions. */
|
---|
89 | RTStrmPrintf(g_pStdErr, "%s: error: ", &g_szrtProcExePath[g_offrtProcName]);
|
---|
90 | RTStrmPrintfV(g_pStdErr, pszFormat, va);
|
---|
91 | if (!strchr(pszFormat, '\n'))
|
---|
92 | RTStrmPrintf(g_pStdErr, "\n");
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | return VINF_SUCCESS;
|
---|
97 | }
|
---|
98 | RT_EXPORT_SYMBOL(RTMsgErrorV);
|
---|
99 |
|
---|
100 |
|
---|