]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/Common/EfiUtilityMsgs.c
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / C / Common / EfiUtilityMsgs.c
index 68cf02469e18a4de9ab9d6f4c4bb037a4f7254f5..f8d2a40be1e19a29149378157c26595cfd74b269 100644 (file)
@@ -1,22 +1,8 @@
 /** @file\r
+EFI tools utility functions to display warning, error, and informational messages\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation\r
-All rights reserved. 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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-Module Name:\r
-\r
-  EfiUtilityMsgs.c\r
-\r
-Abstract:\r
-\r
-  EFI tools utility functions to display warning, error, and informational\r
-  messages.\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 --*/\r
 \r
@@ -29,7 +15,7 @@ Abstract:
 #include "EfiUtilityMsgs.h"\r
 \r
 //\r
-// Declare module globals for keeping track of the the utility's\r
+// Declare module globals for keeping track of the utility's\r
 // name and other settings.\r
 //\r
 STATIC STATUS mStatus                 = STATUS_SUCCESS;\r
@@ -44,18 +30,6 @@ STATIC UINT32 mMaxWarnings            = 0;
 STATIC UINT32 mMaxWarningsPlusErrors  = 0;\r
 STATIC INT8   mPrintLimitsSet         = 0;\r
 \r
-STATIC\r
-VOID\r
-PrintMessage (\r
-  CHAR8   *Type,\r
-  CHAR8   *FileName,\r
-  UINT32  LineNumber,\r
-  UINT32  MessageCode,\r
-  CHAR8   *Text,\r
-  CHAR8   *MsgFmt,\r
-  va_list List\r
-  );\r
-\r
 STATIC\r
 VOID\r
 PrintLimitExceeded (\r
@@ -81,7 +55,7 @@ Arguments:
   at least something valid is not specified.\r
 \r
   FileName - name of the file or application. If not specified, then the\r
-             utilty name (as set by the utility calling SetUtilityName()\r
+             utility name (as set by the utility calling SetUtilityName()\r
              earlier) is used. Otherwise "Unknown utility" is used.\r
 \r
   LineNumber - the line number of error, typically used by parsers. If the\r
@@ -151,12 +125,6 @@ Notes:
   va_start (List, MsgFmt);\r
   PrintMessage ("ERROR", FileName, LineNumber, MessageCode, Text, MsgFmt, List);\r
   va_end (List);\r
-  //\r
-  // Set status accordingly\r
-  //\r
-  if (mStatus < STATUS_ERROR) {\r
-    mStatus = STATUS_ERROR;\r
-  }\r
 }\r
 \r
 VOID\r
@@ -211,12 +179,6 @@ Returns:
   va_start (List, MsgFmt);\r
   PrintMessage ("ERROR", mSourceFileName, mSourceFileLineNum, MessageCode, Text, MsgFmt, List);\r
   va_end (List);\r
-  //\r
-  // Set status accordingly\r
-  //\r
-  if (mStatus < STATUS_ERROR) {\r
-    mStatus = STATUS_ERROR;\r
-  }\r
 }\r
 \r
 VOID\r
@@ -396,7 +358,6 @@ Returns:
   va_end (List);\r
 }\r
 \r
-STATIC\r
 VOID\r
 PrintMessage (\r
   CHAR8   *Type,\r
@@ -417,7 +378,7 @@ Routine Description:
 Arguments:\r
   Type        - "warning" or "error" string to insert into the message to be\r
                 printed. The first character of this string (converted to uppercase)\r
-                is used to preceed the MessageCode value in the output string.\r
+                is used to precede the MessageCode value in the output string.\r
 \r
   FileName    - name of the file where the warning was detected, or the name\r
                 of the application that detected the warning\r
@@ -484,19 +445,22 @@ Notes:
     //\r
     time (&CurrentTime);\r
     NewTime = localtime (&CurrentTime);\r
-    fprintf (stdout, "%04d-%02d-%02d %02d:%02d:%02d",\r
-                     NewTime->tm_year + 1900,\r
-                     NewTime->tm_mon + 1,\r
-                     NewTime->tm_mday,\r
-                     NewTime->tm_hour,\r
-                     NewTime->tm_min,\r
-                     NewTime->tm_sec\r
-                     );\r
+    if (NewTime != NULL) {\r
+      fprintf (stdout, "%04d-%02d-%02d %02d:%02d:%02d",\r
+                       NewTime->tm_year + 1900,\r
+                       NewTime->tm_mon + 1,\r
+                       NewTime->tm_mday,\r
+                       NewTime->tm_hour,\r
+                       NewTime->tm_min,\r
+                       NewTime->tm_sec\r
+                       );\r
+    }\r
     if (Cptr != NULL) {\r
-      sprintf (Line, ": %s", Cptr);\r
+      strcpy (Line, ": ");\r
+      strncat (Line, Cptr, MAX_LINE_LEN - strlen (Line) - 1);\r
       if (LineNumber != 0) {\r
         sprintf (Line2, "(%u)", (unsigned) LineNumber);\r
-        strcat (Line, Line2);\r
+        strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);\r
       }\r
     }\r
   } else {\r
@@ -507,14 +471,25 @@ Notes:
       if (mUtilityName[0] != '\0') {\r
         fprintf (stdout, "%s...\n", mUtilityName);\r
       }\r
-      sprintf (Line, "%s", Cptr);\r
+      strncpy (Line, Cptr, MAX_LINE_LEN - 1);\r
+      Line[MAX_LINE_LEN - 1] = 0;\r
       if (LineNumber != 0) {\r
         sprintf (Line2, "(%u)", (unsigned) LineNumber);\r
-        strcat (Line, Line2);\r
+        strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);\r
       }\r
     } else {\r
       if (mUtilityName[0] != '\0') {\r
-        sprintf (Line, "%s", mUtilityName);\r
+        strncpy (Line, mUtilityName, MAX_LINE_LEN - 1);\r
+        Line[MAX_LINE_LEN - 1] = 0;\r
+      }\r
+    }\r
+\r
+    if (strcmp (Type, "ERROR") == 0) {\r
+      //\r
+      // Set status accordingly for ERROR information.\r
+      //\r
+      if (mStatus < STATUS_ERROR) {\r
+        mStatus = STATUS_ERROR;\r
       }\r
     }\r
   }\r
@@ -523,12 +498,12 @@ Notes:
   // Have to print an error code or Visual Studio won't find the\r
   // message for you. It has to be decimal digits too.\r
   //\r
+  strncat (Line, ": ", MAX_LINE_LEN - strlen (Line) - 1);\r
+  strncat (Line, Type, MAX_LINE_LEN - strlen (Line) - 1);\r
   if (MessageCode != 0) {\r
-    sprintf (Line2, ": %s %04u", Type, (unsigned) MessageCode);\r
-  } else {\r
-    sprintf (Line2, ": %s", Type);\r
+    sprintf (Line2, " %04u", (unsigned) MessageCode);\r
+    strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);\r
   }\r
-  strcat (Line, Line2);\r
   fprintf (stdout, "%s", Line);\r
   //\r
   // If offending text was provided, then print it\r
@@ -545,6 +520,7 @@ Notes:
     vsprintf (Line2, MsgFmt, List);\r
     fprintf (stdout, "  %s\n", Line2);\r
   }\r
+\r
 }\r
 \r
 STATIC\r
@@ -615,7 +591,7 @@ Routine Description:
 \r
 Arguments:\r
   UtilityName  -  name of the utility, which will be printed with all\r
-                  error/warning/debug messags.\r
+                  error/warning/debug messages.\r
 \r
 Returns:\r
   NA\r
@@ -629,12 +605,9 @@ Returns:
   if (UtilityName != NULL) {\r
     if (strlen (UtilityName) >= sizeof (mUtilityName)) {\r
       Error (UtilityName, 0, 0, "application error", "utility name length exceeds internal buffer size");\r
-      strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1);\r
-      mUtilityName[sizeof (mUtilityName) - 1] = 0;\r
-      return ;\r
-    } else {\r
-      strcpy (mUtilityName, UtilityName);\r
     }\r
+    strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1);\r
+    mUtilityName[sizeof (mUtilityName) - 1] = 0;\r
   } else {\r
     Error (NULL, 0, 0, "application error", "SetUtilityName() called with NULL utility name");\r
   }\r