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