mirror of https://github.com/ncroxon/gnu-efi
Add AsciiPrint and AsciiVSPrint
Per https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Library/PrintLib.h AsciiPrint() is the official name of APrint() so declare it as such and define an APrint alias for compatibility. Also add an AsciiVSPrint() to print a formatted ASCII string to a buffer using a va_list. AsciiPrint() too is defined in EDK2's PrintLib.h, though our implementation just invokes the Unicode version and then converts the buffer to ASCII.
This commit is contained in:
parent
ebdde0bc4b
commit
0247cb7cd4
13
inc/efilib.h
13
inc/efilib.h
|
@ -580,11 +580,22 @@ IPrintAt (
|
|||
);
|
||||
|
||||
UINTN
|
||||
APrint (
|
||||
AsciiPrint (
|
||||
IN CONST CHAR8 *fmt,
|
||||
...
|
||||
);
|
||||
|
||||
/* For compatibility with previous versions */
|
||||
#define APrint AsciiPrint
|
||||
|
||||
UINTN
|
||||
AsciiVSPrint(
|
||||
OUT CHAR8 *Str,
|
||||
IN UINTN StrSize,
|
||||
IN CONST CHAR8 *fmt,
|
||||
va_list args
|
||||
);
|
||||
|
||||
VOID
|
||||
ValueToHex (
|
||||
IN CHAR16 *Buffer,
|
||||
|
|
62
lib/print.c
62
lib/print.c
|
@ -405,7 +405,7 @@ _PoolCatPrint (
|
|||
IN OUT POOL_PRINT *spc,
|
||||
IN INTN (EFIAPI *Output)(VOID *context, CHAR16 *str)
|
||||
)
|
||||
// Dispath function for SPrint, PoolPrint, and CatPrint
|
||||
// Dispatch function for SPrint, PoolPrint, and CatPrint
|
||||
{
|
||||
PRINT_STATE ps;
|
||||
|
||||
|
@ -810,7 +810,7 @@ _IPrint (
|
|||
|
||||
|
||||
UINTN
|
||||
APrint (
|
||||
AsciiPrint (
|
||||
IN CONST CHAR8 *fmt,
|
||||
...
|
||||
)
|
||||
|
@ -842,6 +842,64 @@ Returns:
|
|||
}
|
||||
|
||||
|
||||
UINTN
|
||||
AsciiVSPrint (
|
||||
OUT CHAR8 *Str,
|
||||
IN UINTN StrSize,
|
||||
IN CONST CHAR8 *fmt,
|
||||
va_list args
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Prints a formatted ascii string to a buffer using a va_list
|
||||
|
||||
Arguments:
|
||||
|
||||
Str - Output buffer to print the formatted string into
|
||||
|
||||
StrSize - Size of Str. String is truncated to this size.
|
||||
A size of 0 means there is no limit
|
||||
|
||||
fmt - The format string
|
||||
|
||||
args - va_list
|
||||
|
||||
|
||||
Returns:
|
||||
|
||||
String length returned in buffer
|
||||
|
||||
--*/
|
||||
// Use Unicode VSPrint() and convert back to ASCII
|
||||
{
|
||||
CHAR16 *UnicodeStr, *UnicodeFmt;
|
||||
UINTN i, Len;
|
||||
|
||||
UnicodeStr = AllocatePool(StrSize * sizeof(CHAR16));
|
||||
if (!UnicodeStr)
|
||||
return 0;
|
||||
|
||||
UnicodeFmt = PoolPrint(L"%a", fmt);
|
||||
if (!UnicodeFmt) {
|
||||
FreePool(UnicodeStr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Len = VSPrint(UnicodeStr, StrSize, UnicodeFmt, args);
|
||||
FreePool(UnicodeFmt);
|
||||
|
||||
// The strings are ASCII so just do a plain Unicode conversion
|
||||
for (i = 0; i < Len; i++)
|
||||
Str[i] = (CHAR8)UnicodeStr[i];
|
||||
Str[Len] = 0;
|
||||
FreePool(UnicodeStr);
|
||||
|
||||
return Len;
|
||||
}
|
||||
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
PFLUSH (
|
||||
|
|
Loading…
Reference in New Issue