mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-26 23:24:03 +02:00
BaseTools/VolInfo: Fix printf issue using '%ls' in format string
https://bugzilla.tianocore.org/show_bug.cgi?id=257 For GCC compilers, when building with option '-fshort-wchar', wide char string format '%ls' does not work properly for printf() function. The string specified by '%ls' will not be printed. This commit avoids using '%ls' for printf() function and converts the wide char string to char string for printing. Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
parent
0db4acb61a
commit
3883e2cb52
@ -148,6 +148,65 @@ Usage (
|
|||||||
VOID
|
VOID
|
||||||
);
|
);
|
||||||
|
|
||||||
|
UINT32
|
||||||
|
UnicodeStrLen (
|
||||||
|
IN CHAR16 *String
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Returns the length of a null-terminated unicode string.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
String - The pointer to a null-terminated unicode string.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
N/A
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
UINT32 Length;
|
||||||
|
|
||||||
|
for (Length = 0; *String != L'\0'; String++, Length++) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
return Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID
|
||||||
|
Unicode2AsciiString (
|
||||||
|
IN CHAR16 *Source,
|
||||||
|
OUT CHAR8 *Destination
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Convert a null-terminated unicode string to a null-terminated ascii string.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Source - The pointer to the null-terminated input unicode string.
|
||||||
|
Destination - The pointer to the null-terminated output ascii string.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
N/A
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
while (*Source != '\0') {
|
||||||
|
*(Destination++) = (CHAR8) *(Source++);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// End the ascii with a NULL.
|
||||||
|
//
|
||||||
|
*Destination = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (
|
main (
|
||||||
int argc,
|
int argc,
|
||||||
@ -1606,6 +1665,7 @@ Returns:
|
|||||||
UINT32 RealHdrLen;
|
UINT32 RealHdrLen;
|
||||||
CHAR8 *ToolInputFileName;
|
CHAR8 *ToolInputFileName;
|
||||||
CHAR8 *ToolOutputFileName;
|
CHAR8 *ToolOutputFileName;
|
||||||
|
CHAR8 *UIFileName;
|
||||||
|
|
||||||
ParsedLength = 0;
|
ParsedLength = 0;
|
||||||
ToolInputFileName = NULL;
|
ToolInputFileName = NULL;
|
||||||
@ -1714,7 +1774,14 @@ Returns:
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case EFI_SECTION_USER_INTERFACE:
|
case EFI_SECTION_USER_INTERFACE:
|
||||||
printf (" String: %ls\n", (wchar_t *) &((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString);
|
UIFileName = (CHAR8 *) malloc (UnicodeStrLen (((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString) + 1);
|
||||||
|
if (UIFileName == NULL) {
|
||||||
|
Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
Unicode2AsciiString (((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString, UIFileName);
|
||||||
|
printf (" String: %s\n", UIFileName);
|
||||||
|
free (UIFileName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EFI_SECTION_FIRMWARE_VOLUME_IMAGE:
|
case EFI_SECTION_FIRMWARE_VOLUME_IMAGE:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user