VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/misc/message.cpp@ 24825

Last change on this file since 24825 was 24825, checked in by vboxsync, 16 years ago

IPRT: Added RTMsgError, RTMsgErrorV and RTGetOptPrintError.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/* $Id: message.cpp 24825 2009-11-20 14:41:05Z 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.215389.xyz. 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
43RTDECL(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
52
53RTDECL(int) RTMsgErrorV(const char *pszFormat, va_list va)
54{
55 if ( !*pszFormat
56 || !strcmp(pszFormat, "\n"))
57 RTStrmPrintf(g_pStdErr, "\n");
58 else
59 {
60 char *pszMsg;
61 ssize_t cch = RTStrAPrintfV(&pszMsg, pszFormat, va);
62 if (cch >= 0)
63 {
64 /* print it line by line. */
65 char *psz = pszMsg;
66 do
67 {
68 char *pszEnd = strchr(psz, '\n');
69 if (!pszEnd)
70 {
71 RTStrmPrintf(g_pStdErr, "%s: error: %s\n", &g_szrtProcExePath[g_offrtProcName], psz);
72 break;
73 }
74 if (pszEnd == psz)
75 RTStrmPrintf(g_pStdErr, "\n");
76 else
77 {
78 *pszEnd = '\0';
79 RTStrmPrintf(g_pStdErr, "%s: error: %s\n", &g_szrtProcExePath[g_offrtProcName], psz);
80 }
81 psz = pszEnd + 1;
82 } while (*psz);
83 RTStrFree(pszMsg);
84 }
85 else
86 {
87 /* Simple fallback for handling out-of-memory conditions. */
88 RTStrmPrintf(g_pStdErr, "%s: error: ", &g_szrtProcExePath[g_offrtProcName]);
89 RTStrmPrintfV(g_pStdErr, pszFormat, va);
90 if (!strchr(pszFormat, '\n'))
91 RTStrmPrintf(g_pStdErr, "\n");
92 }
93 }
94
95 return VINF_SUCCESS;
96}
97
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette