VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/nocrt-fatal-write-win.cpp@ 103795

Last change on this file since 103795 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: nocrt-fatal-write-win.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - No-CRT - Fatal Message Writing Primitives, Windows.
4 */
5
6/*
7 * Copyright (C) 2022-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "internal/nocrt.h"
42
43#include <iprt/win/windows.h>
44#include <iprt/string.h>
45
46
47/** @todo invent some kind of weak linking with the debug and release
48 * loggers, e.g. theset some innocent function we can call to do
49 * logging and we'll call it if it isn't NULL. */
50
51void rtNoCrtFatalWrite(const char *pchMsg, size_t cchMsg)
52{
53 DWORD cbIgn;
54 WriteFile(GetStdHandle(STD_ERROR_HANDLE), pchMsg, (DWORD)cchMsg, &cbIgn, NULL);
55}
56
57
58void rtNoCrtFatalWriteBegin(const char *pchMsg, size_t cchMsg)
59{
60 rtNoCrtFatalWrite(pchMsg, cchMsg);
61}
62
63
64void rtNoCrtFatalWriteEnd(const char *pchMsg, size_t cchMsg)
65{
66 rtNoCrtFatalWrite(pchMsg, cchMsg);
67}
68
69
70void rtNoCrtFatalWritePtr(void const *pv)
71{
72 char szValue[128];
73#if ARCH_BITS == 64
74 ssize_t cchValue = RTStrFormatU64(szValue, sizeof(szValue), (uintptr_t)pv, 16, 16, 16, RTSTR_F_WIDTH | RTSTR_F_64BIT);
75#elif ARCH_BITS == 32
76 ssize_t cchValue = RTStrFormatU32(szValue, sizeof(szValue), (uintptr_t)pv, 16, 8, 8, RTSTR_F_WIDTH | RTSTR_F_32BIT);
77#else
78# error ARCH_BITS
79#endif
80 rtNoCrtFatalWrite(szValue, (size_t)cchValue);
81}
82
83
84void rtNoCrtFatalWriteX64(uint64_t uValue)
85{
86 char szValue[128];
87 ssize_t cchValue = RTStrFormatU64(szValue, sizeof(szValue), uValue, 16, 0, 0, RTSTR_F_SPECIAL | RTSTR_F_64BIT);
88 rtNoCrtFatalWrite(szValue, (size_t)cchValue);
89}
90
91
92void rtNoCrtFatalWriteX32(uint32_t uValue)
93{
94 char szValue[128];
95 ssize_t cchValue = RTStrFormatU32(szValue, sizeof(szValue), uValue, 16, 0, 0, RTSTR_F_SPECIAL | RTSTR_F_32BIT);
96 rtNoCrtFatalWrite(szValue, (size_t)cchValue);
97}
98
99
100void rtNoCrtFatalWriteRc(int rc)
101{
102 char szValue[128];
103 ssize_t cchValue = RTStrFormatU32(szValue, sizeof(szValue), rc, 10, 0, 0, RTSTR_F_32BIT | RTSTR_F_VALSIGNED);
104 rtNoCrtFatalWrite(szValue, (size_t)cchValue);
105}
106
107void rtNoCrtFatalWriteWinRc(uint32_t rc)
108{
109 char szValue[168];
110 ssize_t cchValue = RTStrFormatU32(szValue, sizeof(szValue), rc, 10, 0, 0, RTSTR_F_32BIT);
111 szValue[cchValue++] = ' ';
112 szValue[cchValue++] = '(';
113 cchValue += RTStrFormatU32(&szValue[cchValue], sizeof(szValue) - cchValue, rc, 16, 0, 0, RTSTR_F_32BIT | RTSTR_F_SPECIAL);
114 szValue[cchValue++] = ')';
115 rtNoCrtFatalWrite(szValue, (size_t)cchValue);
116}
117
118
119void rtNoCrtFatalWriteStr(const char *pszString)
120{
121 if (RT_VALID_PTR(pszString))
122 {
123 size_t cch = 0;
124 while (pszString[cch] != '\0')
125 cch++;
126 rtNoCrtFatalWrite(pszString, cch);
127 }
128 else
129 {
130 rtNoCrtFatalWrite(RT_STR_TUPLE("<pszString="));
131 rtNoCrtFatalWritePtr(pszString);
132 rtNoCrtFatalWrite(RT_STR_TUPLE(">"));
133 }
134}
135
136
137void rtNoCrtFatalMsg(const char *pchMsg, size_t cchMsg)
138{
139 rtNoCrtFatalWriteBegin(pchMsg, cchMsg);
140 rtNoCrtFatalWriteEnd(RT_STR_TUPLE(""));
141}
142
143
144void rtNoCrtFatalMsgWithRc(const char *pchMsg, size_t cchMsg, int rc)
145{
146 rtNoCrtFatalWriteBegin(pchMsg, cchMsg);
147 rtNoCrtFatalWriteRc(rc);
148 rtNoCrtFatalWriteEnd(RT_STR_TUPLE("\r\n"));
149}
150
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