]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiLib/UefiLibPrint.c
Code scrub:
[mirror_edk2.git] / MdePkg / Library / UefiLib / UefiLibPrint.c
1 /** @file
2 Mde UEFI library API implemention.
3 Print to StdErr or ConOut defined in EFI_SYSTEM_TABLE
4
5 Copyright (c) 2007, Intel Corporation<BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 //
17 // Include common header file for this module.
18 //
19 #include "UefiLibInternal.h"
20
21 /**
22 Internal function which prints a formatted Unicode string to the console output device
23 specified by Console
24
25 This function prints a formatted Unicode string to the console output device
26 specified by Console and returns the number of Unicode characters that printed
27 to it. If the length of the formatted Unicode string is greater than PcdUefiLibMaxPrintBufferSize,
28 then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.
29 If Format is NULL, then ASSERT().
30 If Format is not aligned on a 16-bit boundary, then ASSERT().
31
32 @param Format Null-terminated Unicode format string.
33 @param Console The output console.
34 @param Marker VA_LIST marker for the variable argument list.
35
36 @return The number of Unicode characters in the produced
37 output buffer not including the Null-terminator.
38 **/
39
40 STATIC
41 UINTN
42 InternalPrint (
43 IN CONST CHAR16 *Format,
44 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,
45 IN VA_LIST Marker
46 )
47 {
48 UINTN Return;
49 CHAR16 *Buffer;
50 UINTN BufferSize;
51
52 ASSERT (Format != NULL);
53 ASSERT (((UINTN) Format & 0x01) == 0);
54
55 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
56
57 Buffer = (CHAR16 *) AllocatePool(BufferSize);
58 ASSERT (Buffer != NULL);
59
60 Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
61
62 if (Console != NULL && Return > 0) {
63 //
64 // To be extra safe make sure Console has been initialized
65 //
66 Console->OutputString (Console, Buffer);
67 }
68
69 FreePool (Buffer);
70
71 return Return;
72 }
73
74 /**
75 Prints a formatted Unicode string to the console output device specified by
76 ConOut defined in the EFI_SYSTEM_TABLE.
77
78 This function prints a formatted Unicode string to the console output device
79 specified by ConOut in EFI_SYSTEM_TABLE and returns the number of Unicode
80 characters that printed to ConOut. If the length of the formatted Unicode
81 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
82 PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.
83 If Format is NULL, then ASSERT().
84 If Format is not aligned on a 16-bit boundary, then ASSERT().
85
86 @param Format Null-terminated Unicode format string.
87 @param ... VARARG list consumed to process Format.
88
89 @return The number of Unicode characters in the produced
90 output buffer not including the Null-terminator.
91
92 **/
93 UINTN
94 EFIAPI
95 Print (
96 IN CONST CHAR16 *Format,
97 ...
98 )
99 {
100 VA_LIST Marker;
101 UINTN Return;
102
103 VA_START (Marker, Format);
104
105 Return = InternalPrint (Format, gST->ConOut, Marker);
106
107 VA_END (Marker);
108
109 return Return;
110 }
111
112 /**
113 Prints a formatted Unicode string to the console output device specified by
114 StdErr defined in the EFI_SYSTEM_TABLE.
115
116 This function prints a formatted Unicode string to the console output device
117 specified by StdErr in EFI_SYSTEM_TABLE and returns the number of Unicode
118 characters that printed to StdErr. If the length of the formatted Unicode
119 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
120 PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.
121 If Format is NULL, then ASSERT().
122 If Format is not aligned on a 16-bit boundary, then ASSERT().
123
124 @param Format Null-terminated Unicode format string.
125 @param ... VARARG list consumed to process Format.
126
127 @return The number of Unicode characters in the produced
128 output buffer not including the Null-terminator.
129 **/
130
131 UINTN
132 EFIAPI
133 ErrorPrint (
134 IN CONST CHAR16 *Format,
135 ...
136 )
137 {
138 VA_LIST Marker;
139 UINTN Return;
140
141 VA_START (Marker, Format);
142
143 Return = InternalPrint( Format, gST->StdErr, Marker);
144
145 VA_END (Marker);
146
147 return Return;
148 }
149
150
151 /**
152 Internal function which prints a formatted ASCII string to the console output device
153 specified by Console
154
155 This function prints a formatted ASCII string to the console output device
156 specified by Console and returns the number of ASCII characters that printed
157 to it. If the length of the formatted ASCII string is greater than PcdUefiLibMaxPrintBufferSize,
158 then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.
159 If Format is NULL, then ASSERT().
160
161 If Format is NULL, then ASSERT().
162 If Format is not aligned on a 16-bit boundary, then ASSERT().
163
164
165 @param Format Null-terminated ASCII format string.
166 @param Console The output console.
167 @param Marker VA_LIST marker for the variable argument list.
168
169 @return The number of Unicode characters in the produced
170 output buffer not including the Null-terminator.
171
172 **/
173 STATIC
174 UINTN
175 AsciiInternalPrint (
176 IN CONST CHAR8 *Format,
177 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,
178 IN VA_LIST Marker
179 )
180 {
181 UINTN Return;
182 CHAR16 *Buffer;
183 UINTN BufferSize;
184
185 ASSERT (Format != NULL);
186
187 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
188
189 Buffer = (CHAR16 *) AllocatePool(BufferSize);
190 ASSERT (Buffer != NULL);
191
192 Return = UnicodeVSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);
193
194 if (Console != NULL) {
195 //
196 // To be extra safe make sure Console has been initialized
197 //
198 Console->OutputString (Console, Buffer);
199 }
200
201 FreePool (Buffer);
202
203 return Return;
204 }
205
206 /**
207 Prints a formatted ASCII string to the console output device specified by
208 ConOut defined in the EFI_SYSTEM_TABLE.
209
210 This function prints a formatted ASCII string to the console output device
211 specified by ConOut in EFI_SYSTEM_TABLE and returns the number of ASCII
212 characters that printed to ConOut. If the length of the formatted ASCII
213 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
214 PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.
215 If Format is NULL, then ASSERT().
216 If Format is not aligned on a 16-bit boundary, then ASSERT().
217
218 @param Format Null-terminated ASCII format string.
219 @param ... VARARG list consumed to process Format.
220
221 @return The number of Ascii characters in the produced
222 output buffer not including the Null-terminator.
223
224 **/
225 UINTN
226 EFIAPI
227 AsciiPrint (
228 IN CONST CHAR8 *Format,
229 ...
230 )
231 {
232 VA_LIST Marker;
233 UINTN Return;
234
235 VA_START (Marker, Format);
236
237 Return = AsciiInternalPrint( Format, gST->ConOut, Marker);
238
239 VA_END (Marker);
240
241 return Return;
242 }
243
244 /**
245 Prints a formatted ASCII string to the console output device specified by
246 StdErr defined in the EFI_SYSTEM_TABLE.
247
248 This function prints a formatted ASCII string to the console output device
249 specified by StdErr in EFI_SYSTEM_TABLE and returns the number of ASCII
250 characters that printed to StdErr. If the length of the formatted ASCII
251 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
252 PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.
253 If Format is NULL, then ASSERT().
254 If Format is not aligned on a 16-bit boundary, then ASSERT().
255
256 @param Format Null-terminated ASCII format string.
257 @param ... VARARG list consumed to process Format.
258
259 @return The number of Ascii characters in the produced output
260 buffer not including the Null-terminator.
261
262 **/
263 UINTN
264 EFIAPI
265 AsciiErrorPrint (
266 IN CONST CHAR8 *Format,
267 ...
268 )
269 {
270 VA_LIST Marker;
271 UINTN Return;
272
273 VA_START (Marker, Format);
274
275 Return = AsciiInternalPrint( Format, gST->StdErr, Marker);
276
277 VA_END (Marker);
278
279 return Return;
280 }
281