]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/Split/Split.c
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / C / Split / Split.c
index c6f547ca43cbc399cd5ac93370ad4c1f539b5f60..be0ee124bfe0b36a0607dd195e564f6d335fb2e4 100644 (file)
@@ -2,14 +2,8 @@
 \r
   Split a file into two pieces at the request offset.\r
 \r
-Copyright (c) 1999 - 2016, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials are licensed and made available\r
-under the terms and conditions of the BSD License which accompanies this\r
-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
+Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -80,7 +74,7 @@ Returns:
 --*/\r
 {\r
   Version();\r
-  printf ("Copyright (c) 1999-2016 Intel Corporation. All rights reserved.\n");\r
+  printf ("Copyright (c) 1999-2017 Intel Corporation. All rights reserved.\n");\r
   printf ("\n  SplitFile creates two Binary files either in the same directory as the current working\n");\r
   printf ("  directory or in the specified directory.\n");\r
   printf ("\nUsage: \n\\r
@@ -103,13 +97,17 @@ GetSplitValue (
   OUT UINT64 *ReturnValue\r
 )\r
 {\r
-  UINT64 len = strlen(SplitValueString);\r
+  UINT64 len = 0;\r
   UINT64 base = 1;\r
   UINT64 index = 0;\r
   UINT64 number = 0;\r
   CHAR8 lastCHAR = 0;\r
   EFI_STATUS Status = EFI_SUCCESS;\r
 \r
+  if (SplitValueString != NULL){\r
+    len = strlen(SplitValueString);\r
+  }\r
+\r
   if (len == 0) {\r
     return EFI_ABORTED;\r
   }\r
@@ -223,14 +221,15 @@ Returns:
 --*/\r
 {\r
   EFI_STATUS    Status = EFI_SUCCESS;\r
+  INTN          ReturnStatus = STATUS_SUCCESS;\r
   FILE          *In;\r
   CHAR8         *InputFileName = NULL;\r
   CHAR8         *OutputDir = NULL;\r
   CHAR8         *OutFileName1 = NULL;\r
   CHAR8         *OutFileName2 = NULL;\r
   UINT64        SplitValue = (UINT64) -1;\r
-  FILE          *Out1;\r
-  FILE          *Out2;\r
+  FILE          *Out1 = NULL;\r
+  FILE          *Out2 = NULL;\r
   CHAR8         *OutName1 = NULL;\r
   CHAR8         *OutName2 = NULL;\r
   CHAR8         *CurrentDir = NULL;\r
@@ -323,7 +322,7 @@ Returns:
       if (strlen(argv[0]) > 2) {\r
         Status = CountVerboseLevel (&argv[0][2], strlen(argv[0]) - 2, &VerboseLevel);\r
         if (EFI_ERROR (Status)) {\r
-          Error (NULL, 0, 0x1003, NULL, "%s is invaild paramter!", argv[0]);\r
+          Error (NULL, 0, 0x1003, NULL, "%s is invalid parameter!", argv[0]);\r
           return STATUS_ERROR;\r
         }\r
       }\r
@@ -344,9 +343,9 @@ Returns:
       continue;\r
     }\r
     //\r
-    // Don't recognize the paramter.\r
+    // Don't recognize the parameter.\r
     //\r
-    Error (NULL, 0, 0x1003, NULL, "%s is invaild paramter!", argv[0]);\r
+    Error (NULL, 0, 0x1003, NULL, "%s is invalid parameter!", argv[0]);\r
     return STATUS_ERROR;\r
   }\r
 \r
@@ -366,7 +365,8 @@ Returns:
     OutName1 = (CHAR8*)malloc(strlen(InputFileName) + 16);\r
     if (OutName1 == NULL) {\r
       Warning (NULL, 0, 0, NULL, "Memory Allocation Fail.");\r
-      return STATUS_ERROR;\r
+      ReturnStatus = STATUS_ERROR;\r
+      goto Finish;\r
     }\r
     strcpy (OutName1, InputFileName);\r
     strcat (OutName1, "1");\r
@@ -377,7 +377,8 @@ Returns:
     OutName2 = (CHAR8*)malloc(strlen(InputFileName) + 16);\r
     if (OutName2 == NULL) {\r
       Warning (NULL, 0, 0, NULL, "Memory Allocation Fail.");\r
-      return STATUS_ERROR;\r
+      ReturnStatus = STATUS_ERROR;\r
+      goto Finish;\r
     }\r
     strcpy (OutName2, InputFileName);\r
     strcat (OutName2, "2");\r
@@ -389,20 +390,23 @@ Returns:
     //OutputDirSpecified = TRUE;\r
     if (chdir(OutputDir) != 0) {\r
       Warning (NULL, 0, 0, NULL, "Change dir to OutputDir Fail.");\r
-      return STATUS_ERROR;\r
+      ReturnStatus = STATUS_ERROR;\r
+      goto Finish;\r
     }\r
   }\r
 \r
   CurrentDir = (CHAR8*)getcwd((CHAR8*)0, 0);\r
   if (EFI_ERROR(CreateDir(&OutFileName1))) {\r
       Error (OutFileName1, 0, 5, "Create Dir for File1 Fail.", NULL);\r
-      return STATUS_ERROR;\r
+      ReturnStatus = STATUS_ERROR;\r
+      goto Finish;\r
   }\r
   chdir(CurrentDir);\r
 \r
   if (EFI_ERROR(CreateDir(&OutFileName2))) {\r
       Error (OutFileName2, 0, 5, "Create Dir for File2 Fail.", NULL);\r
-      return STATUS_ERROR;\r
+      ReturnStatus = STATUS_ERROR;\r
+      goto Finish;\r
   }\r
   chdir(CurrentDir);\r
   free(CurrentDir);\r
@@ -411,14 +415,16 @@ Returns:
   if (Out1 == NULL) {\r
     // ("Unable to open file \"%s\"\n", OutFileName1);\r
     Error (OutFileName1, 0, 1, "File open failure", NULL);\r
-    return STATUS_ERROR;\r
+    ReturnStatus = STATUS_ERROR;\r
+    goto Finish;\r
   }\r
 \r
   Out2 = fopen (LongFilePath (OutFileName2), "wb");\r
   if (Out2 == NULL) {\r
     // ("Unable to open file \"%s\"\n", OutFileName2);\r
     Error (OutFileName2, 0, 1, "File open failure", NULL);\r
-    return STATUS_ERROR;\r
+    ReturnStatus = STATUS_ERROR;\r
+    goto Finish;\r
   }\r
 \r
   for (Index = 0; Index < SplitValue; Index++) {\r
@@ -439,15 +445,22 @@ Returns:
     fputc (CharC, Out2);\r
   }\r
 \r
+Finish:\r
   if (OutName1 != NULL) {\r
     free(OutName1);\r
   }\r
   if (OutName2 != NULL) {\r
     free(OutName2);\r
   }\r
-  fclose (In);\r
-  fclose (Out1);\r
-  fclose (Out2);\r
+  if (In != NULL) {\r
+    fclose (In);\r
+  }\r
+  if (Out1 != NULL) {\r
+    fclose (Out1);\r
+  }\r
+  if (Out2 != NULL) {\r
+    fclose (Out2);\r
+  }\r
 \r
-  return STATUS_SUCCESS;\r
+  return ReturnStatus;\r
 }\r