]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/Dxe/PrintLite/StdErr.c
EdkCompatibilityPkg/PrintLite: Fix ErrorPrint() wrong NULL char check
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Dxe / PrintLite / StdErr.c
1 /*++
2
3 Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 StdErr.c
15
16 Abstract:
17
18 Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
19 simple implemenation of SPrint() and Print() to support debug.
20
21 You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
22 time. This makes the implementation very simple.
23
24 VSPrint, Print, SPrint format specification has the follwoing form
25
26 %[flags][width]type
27
28 flags:
29 '-' - Left justify
30 '+' - Prefix a sign
31 ' ' - Prefix a blank
32 ',' - Place commas in numberss
33 '0' - Prefix for width with zeros
34 'l' - UINT64
35 'L' - UINT64
36
37 width:
38 '*' - Get width from a UINTN argumnet from the argument list
39 Decimal number that represents width of print
40
41 type:
42 'X' - argument is a UINTN hex number, prefix '0'
43 'x' - argument is a hex number
44 'd' - argument is a decimal number
45 'a' - argument is an ascii string
46 'S','s' - argument is an Unicode string
47 'g' - argument is a pointer to an EFI_GUID
48 't' - argument is a pointer to an EFI_TIME structure
49 'c' - argument is an ascii character
50 'r' - argument is EFI_STATUS
51 '%' - Print a %
52
53 --*/
54
55 #include "Tiano.h"
56 #include "EfiDriverLib.h"
57 #include "EfiCommonLib.h"
58 #include "EfiPrintLib.h"
59 #include "Print.h"
60
61
62 UINTN
63 ErrorPrint (
64 IN CONST CHAR16 *ErrorString,
65 IN CONST CHAR8 *Format,
66 ...
67 )
68 /*++
69
70 Routine Description:
71
72 Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
73 characters.
74
75 Arguments:
76
77 ErrorString - String of error infomation.
78
79 Format - Ascii format string see file header for more details.
80
81 ... - Vararg list consumed by processing Format.
82
83 Returns:
84
85 Number of characters printed.
86
87 --*/
88 {
89 UINTN Return;
90 VA_LIST Marker;
91 UINTN Index;
92 UINTN MaxIndex;
93 CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
94 CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
95
96 MaxIndex = EfiAsciiStrLen ((CHAR8 *) Format);
97 if (MaxIndex >= EFI_DRIVER_LIB_MAX_PRINT_BUFFER) {
98 //
99 // Format string was too long for use to process.
100 //
101 return 0;
102 }
103
104 if (ErrorString != NULL) {
105 if (gST->StdErr != NULL) {
106 //
107 // To be extra safe make sure StdErr has been initialized
108 //
109 gST->StdErr->SetAttribute (gST->StdErr, EFI_TEXT_ATTR (EFI_RED, EFI_BLACK));
110 gST->StdErr->OutputString (gST->StdErr, (CHAR16 *) ErrorString);
111 gST->StdErr->SetAttribute (gST->StdErr, EFI_TEXT_ATTR (EFI_WHITE, EFI_BLACK));
112 }
113 }
114
115 for (Index = 0; Index < MaxIndex; Index++) {
116 UnicodeFormat[Index] = (CHAR16) Format[Index];
117 }
118
119 UnicodeFormat[Index] = 0;
120
121 VA_START (Marker, Format);
122 Return = VSPrint (Buffer, sizeof (Buffer), UnicodeFormat, Marker);
123 VA_END (Marker);
124
125 //
126 // Need to convert to Unicode to do an OutputString
127 //
128
129 if (gST->StdErr != NULL) {
130 //
131 // To be extra safe make sure StdErr has been initialized
132 //
133 gST->StdErr->OutputString (gST->StdErr, Buffer);
134 }
135
136 return Return;
137 }
138
139
140 UINTN
141 Aprint (
142 IN CONST CHAR8 *Format,
143 ...
144 )
145 /*++
146
147 Routine Description:
148
149 Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
150 characters.
151
152 Arguments:
153
154 Format - Ascii format string see file header for more details.
155
156 ... - Vararg list consumed by processing Format.
157
158 Returns:
159
160 Number of characters printed.
161
162 --*/
163 {
164 UINTN Return;
165 VA_LIST Marker;
166 UINTN Index;
167 UINTN MaxIndex;
168 CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
169 CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
170
171 MaxIndex = EfiAsciiStrLen ((CHAR8 *) Format);
172 if (MaxIndex >= EFI_DRIVER_LIB_MAX_PRINT_BUFFER) {
173 //
174 // Format string was too long for use to process.
175 //
176 return 0;
177 }
178
179 for (Index = 0; Index <= MaxIndex; Index++) {
180 UnicodeFormat[Index] = (CHAR16) Format[Index];
181 }
182
183 VA_START (Marker, Format);
184 Return = VSPrint (Buffer, sizeof (Buffer), UnicodeFormat, Marker);
185 VA_END (Marker);
186
187 //
188 // Need to convert to Unicode to do an OutputString
189 //
190
191 if (gST->ConOut != NULL) {
192 //
193 // To be extra safe make sure ConOut has been initialized
194 //
195 gST->ConOut->OutputString (gST->ConOut, Buffer);
196 }
197
198 return Return;
199 }
200
201
202 UINTN
203 Print (
204 IN CONST CHAR16 *Format,
205 ...
206 )
207 /*++
208
209 Routine Description:
210
211 Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
212 characters.
213
214 Arguments:
215
216 Format - Ascii format string see file header for more details.
217
218 ... - Vararg list consumed by processing Format.
219
220 Returns:
221
222 Number of characters printed.
223
224 --*/
225 {
226 UINTN Return;
227 VA_LIST Marker;
228 CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
229
230 VA_START (Marker, Format);
231 Return = VSPrint (Buffer, sizeof (Buffer), Format, Marker);
232 VA_END (Marker);
233
234 if (gST->ConOut != NULL) {
235 //
236 // To be extra safe make sure ConOut has been initialized
237 //
238 gST->ConOut->OutputString (gST->ConOut, Buffer);
239 }
240
241 return Return;
242 }
243
244 UINTN
245 UPrint (
246 IN CONST CHAR16 *Format,
247 ...
248 )
249 /*++
250
251 Routine Description:
252
253 Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
254 characters.
255
256 Arguments:
257
258 Format - Ascii format string see file header for more details.
259
260 ... - Vararg list consumed by processing Format.
261
262 Returns:
263
264 Number of characters printed.
265
266 --*/
267 {
268 UINTN Return;
269 VA_LIST Marker;
270 CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
271
272 VA_START (Marker, Format);
273 Return = VSPrint (Buffer, sizeof (Buffer), Format, Marker);
274 VA_END (Marker);
275
276 if (gST->ConOut != NULL) {
277 //
278 // To be extra safe make sure ConOut has been initialized
279 //
280 gST->ConOut->OutputString (gST->ConOut, Buffer);
281 }
282
283 return Return;
284 }