]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/VolInfo/VolInfo.c
BaseTools/GenVtf & VolInfo: Fix build fail for 'snprintf' not defined
[mirror_edk2.git] / BaseTools / Source / C / VolInfo / VolInfo.c
index 46c72123c87538f8457b4d8fd835c4a9a70edef1..2647cbb73a176c04b605f52ab661df272fa29438 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 The tool dumps the contents of a firmware volume\r
 \r
-Copyright (c) 1999 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -148,6 +148,65 @@ Usage (
   VOID\r
   );\r
 \r
+UINT32\r
+UnicodeStrLen (\r
+  IN CHAR16 *String\r
+  )\r
+  /*++\r
+\r
+  Routine Description:\r
+\r
+  Returns the length of a null-terminated unicode string.\r
+\r
+  Arguments:\r
+\r
+    String - The pointer to a null-terminated unicode string.\r
+\r
+  Returns:\r
+\r
+    N/A\r
+\r
+  --*/\r
+{\r
+  UINT32  Length;\r
+\r
+  for (Length = 0; *String != L'\0'; String++, Length++) {\r
+    ;\r
+  }\r
+  return Length;\r
+}\r
+\r
+VOID\r
+Unicode2AsciiString (\r
+  IN  CHAR16 *Source,\r
+  OUT CHAR8  *Destination\r
+  )\r
+  /*++\r
+\r
+  Routine Description:\r
+\r
+  Convert a null-terminated unicode string to a null-terminated ascii string.\r
+\r
+  Arguments:\r
+\r
+    Source      - The pointer to the null-terminated input unicode string.\r
+    Destination - The pointer to the null-terminated output ascii string.\r
+\r
+  Returns:\r
+\r
+    N/A\r
+\r
+  --*/\r
+{\r
+  while (*Source != '\0') {\r
+    *(Destination++) = (CHAR8) *(Source++);\r
+  }\r
+  //\r
+  // End the ascii with a NULL.\r
+  //\r
+  *Destination = '\0';\r
+}\r
+\r
 int\r
 main (\r
   int       argc,\r
@@ -1606,6 +1665,7 @@ Returns:
   UINT32              RealHdrLen;\r
   CHAR8               *ToolInputFileName;\r
   CHAR8               *ToolOutputFileName;\r
+  CHAR8               *UIFileName;\r
 \r
   ParsedLength = 0;\r
   ToolInputFileName = NULL;\r
@@ -1714,7 +1774,14 @@ Returns:
       break;\r
 \r
     case EFI_SECTION_USER_INTERFACE:\r
-      printf ("  String: %ls\n", (wchar_t *) &((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString);\r
+      UIFileName = (CHAR8 *) malloc (UnicodeStrLen (((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString) + 1);\r
+      if (UIFileName == NULL) {\r
+        Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      Unicode2AsciiString (((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString, UIFileName);\r
+      printf ("  String: %s\n", UIFileName);\r
+      free (UIFileName);\r
       break;\r
 \r
     case EFI_SECTION_FIRMWARE_VOLUME_IMAGE:\r
@@ -2175,8 +2242,7 @@ Returns:
 {\r
   FILE              *Fptr;\r
   CHAR8             Line[MAX_LINE_LEN];\r
-  CHAR8             *FormatString;\r
-  INTN              FormatLength;\r
+  CHAR8             FormatString[MAX_LINE_LEN];\r
   GUID_TO_BASENAME  *GPtr;\r
 \r
   if ((Fptr = fopen (LongFilePath (FileName), "r")) == NULL) {\r
@@ -2187,23 +2253,8 @@ Returns:
   //\r
   // Generate the format string for fscanf\r
   //\r
-  FormatLength = snprintf (\r
-                   NULL,\r
-                   0,\r
-                   "%%%us %%%us",\r
-                   (unsigned) sizeof (GPtr->Guid) - 1,\r
-                   (unsigned) sizeof (GPtr->BaseName) - 1\r
-                   ) + 1;\r
-\r
-  FormatString = (CHAR8 *) malloc (FormatLength);\r
-  if (FormatString == NULL) {\r
-    fclose (Fptr);\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  snprintf (\r
+  sprintf (\r
     FormatString,\r
-    FormatLength,\r
     "%%%us %%%us",\r
     (unsigned) sizeof (GPtr->Guid) - 1,\r
     (unsigned) sizeof (GPtr->BaseName) - 1\r
@@ -2215,7 +2266,6 @@ Returns:
     //\r
     GPtr = malloc (sizeof (GUID_TO_BASENAME));\r
     if (GPtr == NULL) {\r
-      free (FormatString);\r
       fclose (Fptr);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
@@ -2232,7 +2282,6 @@ Returns:
     }\r
   }\r
 \r
-  free (FormatString);\r
   fclose (Fptr);\r
   return EFI_SUCCESS;\r
 }\r